This week in #dev (May 16, 2025)

Welcome to another edition of This Week in #dev, a series of posts where we bring some of our most interesting Slack conversations to the public.

Javascript floating-point precision quirk

Diego Oliveira points out that JavaScript can produce unexpected results with floating-point precision, such as the calculation 6000 * 1.1 yielding 6600.000000000001. JavaScript (and many other languages) uses the IEEE 754 standard for floating-point arithmetic, which can lead to these quirks.

Dave Iverson explains that things like BigInt are available in JavaScript but they don’t have good interoperability with standard Number primitives. He recommends using currency.js to deal with currency. Valerie Burzynski suggests the Money gem for Ruby.

Using .rb files for dynamic translations with I18n gem

Matheus Richard shares a tip: You can use .rb files for translations with the Rails’ I18n gem. This can be when you want a translation to contain a dynamic value but you can’t control the callsite (it comes from a gem, for example). Return a hash from the Ruby file and you can access the value via I18n.t as you would with a YAML file.

# config/locales/en.rb
{
  hello: "#{Rails.config.x.app_name} says hello",
}

Rails’ DateAndTime::Calculations#all_day method

Chad Pytel learned about the [DateAndTime::Calculations#all_day method] provided by Rails. It returns a Range representing the whole day of the current date/time.

Time.current.all_day
# => 2025-05-23 00:00:00.000000000 UTC +00:00..2025-05-23 23:59:59.999999999 UTC +00:00

Matheus adds that there are other methods like all_week, all_month, and all_year available too.

Thanks

This edition was brought to you by Chad Pytel, Dave Iverson, Diego Oliveira, Matheus Richard, and Valerie Burzynski. Thanks to all contributors! 🎉