---
title: 'This week in #dev (May 16, 2025)'
teaser: 'JavaScript floating-point precision quirk, using `.rb` files for translations,
  and Rails'' `all_day` method.

  '
tags: this week in dev,javascript,til
author: thoughtbot
published_on: 2025-05-30
---

Welcome to another edition of [This Week in #dev](https://thoughtbot.com/blog/tags/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][diego] 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][dave] 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](https://currency.js.org/) to deal
with currency. [Valerie Burzynski][valerie] suggests the [Money gem](https://github.com/RubyMoney/money) for Ruby.

[the IEEE 754 standard]: https://en.wikipedia.org/wiki/IEEE_754
[diego]: https://thoughtbot.com/blog/authors/diego-oliveira
[dave]: https://thoughtbot.com/blog/authors/dave-iverson
[valerie]: https://thoughtbot.com/blog/authors/valerie-burzynski

## Using `.rb` files for dynamic translations with I18n gem

[Matheus Richard][matheus] 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.

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

[I18n gem]: https://guides.rubyonrails.org/i18n.html
[matheus]: https://thoughtbot.com/blog/authors/matheus-richard

## Rails' `DateAndTime::Calculations#all_day` method

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

[chad]: https://thoughtbot.com/blog/authors/chad-pytel
[`DateAndTime::Calculations#all_day method]: https://api.rubyonrails.org/classes/DateAndTime/Calculations.html#method-i-all_day

```ruby
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][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][chad], [Dave Iverson][dave],
[Diego Oliveira][diego], [Matheus Richard][matheus], and [Valerie
Burzynski][valerie]. Thanks to all contributors! 🎉
