# Floating Point Math || 0.1+0.2=0.30000000000000004 || Tech OH How/Why does this happened ?

As we know that you computer or any devices understood and work in binary and binary is base 2 . And the number system we human used  to use is decimal number system in most of the time. And you may also know that the decimal point we enter in computer is converted to binary system so that our computer understood it and give us the output of our input. Computers can only naturally stores integers , so they need some way of representing decimal numbers and this representation arrives with some degree of inaccuracy or unreliable. That is why 0.1+0.2 is not equals to 0.3.

If you are thinking it’s difficult to understood about this than please drink a glass of cold water and make yourself cool first because it’s very easy if you give your best focus while reading this. We have a base 10 system and it can only express fractions that uses a prime factor of the base (10). And the prime factor of the base(10) are 2 and  5. For ex :- 1/2 , 1/4 , 1/8 and 1/10 can  be expressed clearly because the denominators all use the prime factor of 10 . But 1/3 , 1/6 and 1/9 , this all are repeating decimals because their denominators use a prime factor of 3 or 7. And we have already talk something about the binary or base 10 the prime factor is only 2. So you guys maybe clarify that we can express fraction clearly which contain 2 as a prime factor . In the binary number  system or base 10 , 1/2 , 1/4 , 1/8 would all be  expressed  cleanly as decimal  whereas 1/5 or 1/10 would be repeating decimals in the base 2 or binary system in which the computer is operating in . When you do math on these repeating decimals, you end up with leftovers which carry over when you convert the computer’s base 2 (binary) number into a more human readable base 10 number. So this all happened while converting the decimal to binary .

## Some examples for different programming are :-

Language Code Result
 C ``````#include int main(int argc, char** argv) { printf("%.17f\n", .1+.2); return 0; }`````` 0.3
 C++ ``````#include std::cout << std::setprecision(17) << 0.1 + 0.2`````` 0.3
 Mathematica ``0.1 + 0.2               `` 0.3
 Python 3 ``print(.1 + .2)              `` And ``.1 + .2`` 0.30000000000000004 And0.30000000000000004