# Strange results..?

**URL:** <https://www.ruby-forum.com/t/strange-results/131871>\
**Category:** Ruby\
**Created:** [March 14, 2008, 12:15am UTC](https://www.ruby-forum.com/t/strange-results/131871 "2008-03-14T00:15:39Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![psy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/e9a140/32.png) [@psy](https://www.ruby-forum.com/u/psy)\
**Post date:** [March 14, 2008, 12:15am UTC](https://www.ruby-forum.com/t/strange-results/131871/1 "2008-03-14T00:15:39Z")

</div>

Hello people,

Here I get some strange (for me) results :

irb(main):012:0\> 0.4 - 0.3 - 0.1  
=\> 2.77555756156289e-17

irb(main):013:0\> 0.5 - 0.4 - 0.1  
=\> -2.77555756156289e-17

irb(main):017:0\> 0.2 + 0.7 - 0.9  
=\> -1.11022302462516e-16

Can somebody explain what happens here or point me some place where i  
can get information for this topic?  
Thanks in advance!

---

<div class="post-metadata">

**Author:** ![psy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/e9a140/32.png) [@psy](https://www.ruby-forum.com/u/psy)\
**Post date:** [March 14, 2008, 12:43am UTC](https://www.ruby-forum.com/t/strange-results/131871/2 "2008-03-14T00:43:11Z")

</div>

On Mar 13, 5:59 pm, psy [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> =\> -2.77555756156289e-17
> 
> irb(main):017:0\> 0.2 + 0.7 - 0.9  
> =\> -1.11022302462516e-16
> 
> Can somebody explain what happens here or point me some place where i  
> can get information for this topic?  
> Thanks in advance!

> **[Floating-point arithmetic | Accuracy problems](https://en.wikipedia.org/wiki/Floating_point#Accuracy_problems)**
>
> The fact that floating-point numbers cannot accurately represent all real numbers, and that floating-point operations cannot accurately represent true arithmetic operations, leads to many surprising situations. This is related to the finite precision with which computers generally represent numbers.
> For example, the decimal numbers 0.1 and 0.01 cannot be represented exactly as binary floating-point numbers. In the IEEE 754 binary32 format with its 24-bit significand, the result of attempting to ...
