A lot of good answers have been posted, but I'd like to append one more.
Not all numbers can be represented via floats/doubles For example, the number "0.2" will be represented as "0.200000003" in single precision in IEEE754 float point standard.
Model for store real numbers under the hood represent float numbers as
Even though you can type 0.2
easily, FLT_RADIX
and DBL_RADIX
is 2; not 10 for a computer with FPU which uses "IEEE Standard for Binary Floating-Point Arithmetic "IEEE Standard for Binary Floating-Point Arithmetic (ISO/IEEE Std 754-1985)"(ISO/IEEE Std 754-1985)".
So it is a bit hard to represent such numbers exactly. Even if you specify this variable explicitly without any intermediate calculation.