Python Forum

Full Version: float multiplication - unexpected output
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello,

I have a unexpected output on a simple multiplication:
0.55*50000
Output:
27500.000000000004
While if I run an equivalent expression
0.55*5*10000
Output:
27500.0
Which is the right output. Is is also the case for other expressions like : 0.55*100 that gives: 55.00000000000001
Anybody knows what this is due to ?

Many thanks,

Inès
floating point is multiplication of two numbers, an integer times an exponent and therefore is a close approximation, not exact
Quote:Which is the right output.
Both are in their situation.
You need to learn more about floating point numbers.
Floating point numbers can't represent all decimal fractions.


import webbrowser
webbrowser.open(str(0.1 + 0.2) + '.com')
http://0.30000000000000004.com/


If you need something, which does not have this problem: decimal fractions