You certainly know the calculator feature of google.

I saw today many bloggers reporting from Google Blogoscoped that google cannot subtract. Look at the picture.
Google substraction

The problem has nothing to do with google. Take the same operation and try to play with some programming languages, you will get the same result.

  • Ruby: 1 - 0.9 - 0.1 = -2.77555756156289e-17

  • PHP(4.4): 1 - 0.9 - 0.1 = -2.7755575615629e-17

  • JavaScript:1 - 0.9 - 0.1 = -2.7755575615628914e-17

  • VbScript: 1 - 0.9 - 0.1 = -2,77555756156289E-17

  • Java2: 1 - 0.9 - 0.1 = -2.7755575615628914E-17

  • Perl 5: 1 - 0.9 - 0.1 = -2.77555756156289e-017

Try other languages if you want, I will be surprised if you get (Zero) the correct answer.

So, why all these programming languages give the wrong answer ?

The IEEE 754 (IEEE = Institute of Electrical and Electronics Engineers) standard is a method of storing floating-point numbers in a compact way that is easy to manipulate. This standard is used by Intel coprocessors and most PC-based programs that implement floating-point math.

IEEE 754 specifies that numbers be stored in binary format to reduce storage requirements and allow the built-in binary arithmetic instructions that are available on all microprocessors to process the data in a relatively rapid fashion. However, some numbers that are simple, nonrepeating decimal numbers are converted into repeating binary numbers that cannot be stored with perfect accuracy.

For example, the number 1/10 can be represented in a decimal number system with a simple decimal: .1
However, the same number in binary format becomes the repeating binary decimal: .0001100011000111000111 (and so on)

This number cannot be represented in a finite amount of space. Therefore, this number is rounded down by approximately -2.78E-17 when it is stored.

If several arithmetic operations are performed to obtain a given result, these rounding errors may be cumulative.

So that's the why of the problem.

Solution: To minimize any effects of floating point arithmetic storage inaccuracy, use the Round() function to round numbers to the number of decimal places that is required by your calculation. For example, if you are working with currency, you would likely round to 2 decimal places:

=ROUND(1-0.9-0.1,2)

Update: This article is updated. I have written a post entitled "Google can subtract" because Google has corrected the problem.