Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 234
Metariat Avatar asked Sep 07 '25 05:09

Metariat


1 Answers

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

like image 82
tigeravatar Avatar answered Sep 08 '25 23:09

tigeravatar