Project

General

Profile

Actions

Bug #19321

closed

BigDecimal multiplication giving different result since Ruby 3.1

Added by alexandruanca (Alexandru Anca) almost 2 years ago. Updated almost 2 years ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:111708]

Description

I have this math operation 120.to_d * 0.07 and I noticed that since upgrading to Ruby 3.1 I get different results. I would expect to get the same result as in previous versions.

rbenv local 3.0.3
➜  irb
require 'bigdecimal/util.rb'
(120.to_d * 0.07).to_s('F')
=> "8.4000000000000012"
rbenv local 3.1.3
✗ irb
require 'bigdecimal/util.rb'
(120.to_d * 0.07).to_s('F')
=> "8.4"

It looks like the change has been introduced in Ruby 3.1. I tested Ruby 2.7.0 and I get the same result as in 3.0 ("8.4000000000000012")
I saw in the release notes that there were changes to bigdecimal so I am not sure if this is expected or it's a bug

Actions

Also available in: Atom PDF

Like0
Like0Like0Like1Like0