We are used to seeing numbers in decimal(base-10) notation, such that each fraction is represented as a sum of powers of 10.
Above is the base-10 representation, we represent this in the decimal expression as: 0.125
Computers usually store values in binary notation, so that each number is expressed as a sum of powers of 2:
In a base-2 representation, we can write this 0.001, The value 0.125=0.001 happens to be one number which both binary and decimal notation can represent in a finite number of digits.
In the base-10 representation of numbers, you are probably familiar with numbers that can’t be expressed in a finite number of digits. For example, dividing 1 by 3 gives, in standard decimal notation:
The 3s go on forever: that is, infinite number of digits are required to truly represent this quotient.
Similarly, there are numbers for which binary representations require an infinite number of digits. For example:
Just as decimal notation requires an infinite number of digits to perfectly represent 1/3, binary notation requires an infinite number of digits to represent 1/10. Python internally truncates these representations at 52 bits beyond the first nonzero bit on most of the systems. The best way to deal with it is to always keep in mind that floating-point arithmetic is approximate, and never rely on exact equality tests with floating-point values.
Precision Rounding Error
If we try to round value 2.675 to two decimal places we get: 2.67