# Math correctness

**URL:** <https://rubytalk.org/t/math-correctness/73488>\
**Category:** ruby-talk\
**Created:** [27 February 2016 10:22 UTC](https://rubytalk.org/t/math-correctness/73488 "2016-02-27T10:22:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![A\_Berger](https://avatars.discourse-cdn.com/v4/letter/a/e9c0ed/32.png) [@A\_Berger](https://rubytalk.org/u/A_Berger)\
**Post date:** [27 February 2016 10:22 UTC](https://rubytalk.org/t/math-correctness/73488/1 "2016-02-27T10:22:14Z")

</div>

Hello  
Having 10000.0/33\*5\*11\*3  
using Ruby 1.9.3 I get 50000.0 exactly,  
using ruby 2.1 (and above) I get 49999.999...  
same with other calculations  
- everytime older versions deliver better results!

I dont know what was changed,  
so perhaps Float should be back(down)graded???

Berg

---

<div class="post-metadata">

**Author:** ![stomar](https://avatars.discourse-cdn.com/v4/letter/s/41988e/32.png) [@stomar](https://rubytalk.org/u/stomar)\
**Post date:** [27 February 2016 10:35 UTC](https://rubytalk.org/t/math-correctness/73488/2 "2016-02-27T10:35:08Z")

</div>

I get 49999.9... also for ruby-2.0.0-p643 and ruby-1.9.3-p551.

Anyway, you need to keep in mind that floating point calculations  
are almost always affected by rounding errors, unavoidably.

Use BigDecimal for arbitrary precision decimal numbers.

Regards,  
Marcus

> **···**
>
> Am 27.02.2016 um 11:22 schrieb A Berger:
> 
> > Having 10000.0/33\*5\*11\*3  
> > using Ruby 1.9.3 I get 50000.0 exactly,  
> > using ruby 2.1 (and above) I get 49999.999...

---

<div class="post-metadata">

**Author:** ![A\_Berger](https://avatars.discourse-cdn.com/v4/letter/a/e9c0ed/32.png) [@A\_Berger](https://rubytalk.org/u/A_Berger)\
**Post date:** [27 February 2016 11:39 UTC](https://rubytalk.org/t/math-correctness/73488/3 "2016-02-27T11:39:23Z")

</div>

I have done it with irb  
RUBY\_VERSION  
1.9.3  
says 50000.0 (exactly)

Thanks for bigdec!
