From: shugo@... Date: 2015-02-17T03:05:23+00:00 Subject: [ruby-core:68134] [Ruby trunk - Bug #10850] BigDecimal division incorrect Issue #10850 has been updated by Shugo Maeda. Priority changed from High to Normal Elyasin Shaladi wrote: > I tried this in Ruby 2.1.4, 2.1.5 and 2.2.0, but in none of the versions it seems correct to me. > > irb(main):041:0* amount1 = BigDecimal("241.3") > => # > > irb(main):042:0> amount2 = BigDecimal("1800") > => # > > irb(main):043:0> rate = amount1 / amount2 > => # > > irb(main):044:0> rate * amount2 #should return amount1 = 241.3 in BigDecimal, but it does not > => # > > > My guess is that there is a bug in the BigDecimal implementation. The result of 241.3 / 1800 is a recurring decimal 0.1340555555....., which can't be represented exactly by a BigDecimal. Please use Rational if you need an exact representation of 241.3 / 1800. ---------------------------------------- Bug #10850: BigDecimal division incorrect https://bugs.ruby-lang.org/issues/10850#change-51519 * Author: Elyasin Shaladi * Status: Open * Priority: Normal * Assignee: ruby-core * ruby -v: ruby 2.2.0p0 (2014-12-25 revision 49005) [x86_64-linux] * Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN ---------------------------------------- I tried this in Ruby 2.1.4, 2.1.5 and 2.2.0, but in none of the versions it seems correct to me. irb(main):041:0* amount1 = BigDecimal("241.3") => # irb(main):042:0> amount2 = BigDecimal("1800") => # irb(main):043:0> rate = amount1 / amount2 => # irb(main):044:0> rate * amount2 #should return amount1 = 241.3 in BigDecimal, but it does not => # My guess is that there is a bug in the BigDecimal implementation. -- https://bugs.ruby-lang.org/