Metariat
Metariat

Reputation: 532

How can 0.2 + 0.1 be equal to 0.3 in Excel?

I understand perfectly why 0.1 + 0.2 is not equal to 0.3 due to the floating point. In most of programming languages, 0.1 + 0.2 == 0.3 is False.

But in Excel if(0.1 + 0.2 == 0.3; 1; 0) gives 1

Upvotes: 4

Views: 577

Answers (1)

tigeravatar
tigeravatar

Reputation: 26650

The reason this happens in Excel is because Excel only keeps track of 15 digits of precision. Floating point math for 0.2 + 0.1 results in 0.30000000000000004, and that 4 way out there is the 17th digit. That means Excel just truncates everything after the 15th 0 and is left with 0.300000000000000 which = 0.3

See here for more info: https://en.wikipedia.org/wiki/Numeric_precision_in_Microsoft_Excel

Upvotes: 8

Related Questions