binary floating-point arithmetic holds many surprises like this the problem with " is explained in precise detail belowin the "representation errorsection see the perils of floating point for more complete account of other common surprises as that says near the end"there are no easy answers stilldon' be unduly wary of floating-pointthe errors in python float operations are inherited from the floating-point hardwareand on most machines are on the order of no more than part in ** per operation that' more than adequate for most tasksbut you do need to keep in mind that it' not decimal arithmetic and that every float operation can suffer new rounding error while pathological cases do existfor most casual use of floating-point arithmetic you'll see the result you expect in the end if you simply round the display of your final results to the number of decimal digits you expect str(usually sufficesand for finer control see the str format(method' format specifiers in formatstrings for use cases which require exact decimal representationtry using the decimal module which implements decimal arithmetic suitable for accounting applications and high-precision applications another form of exact arithmetic is supported by the fractions module which implements arithmetic based on rational numbers (so the numbers like / can be represented exactlyif you are heavy user of floating point operations you should take look at the numerical python package and many other packages for mathematical and statistical operations supplied by the scipy project see <python provides tools that may help on those rare occasions when you really do want to know the exact value of float the float as_integer_ratio(method expresses the value of float as fractionx as_integer_ratio(( since the ratio is exactit can be used to losslessly recreate the original valuex = true the float hex(method expresses float in hexadecimal (base )again giving the exact value stored by your computerx hex(' ep+ this precise hexadecimal representation can be used to reconstruct the float value exactlyx =float fromhex(' ep+ 'true since the representation is exactit is useful for reliably porting values across different versions of python (platform independenceand exchanging data with other languages that support the same format (such as java and another helpful tool is the math fsum(function which helps mitigate loss-of-precision during summation it tracks "lost digitsas values are added onto running total that can make difference in overall accuracy so that the errors do not accumulate to the point where they affect the final totalsum([ = false math fsum([ = true