Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 float multiplication - unexpected output
#1
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
Quote
#2
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.
Quote
#3
See this thread or this one
Quote
#4
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
Larz60+ and Gribouillis like this post
My code examples are always for Python >=3.6.0
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Unexpected output palladium 4 326 Jan-11-2020, 03:26 PM
Last Post: palladium
  Unexpected output: if statement CabbageMan 1 286 Sep-04-2019, 04:12 PM
Last Post: ThomasL
  Comaparing Float Values of Dictionary Against A Float Value & Pick Matching Key firebird 2 555 Jul-25-2019, 11:32 PM
Last Post: scidam
  Unexpected Output using classes and inheritance langley 2 421 Jul-04-2019, 09:33 AM
Last Post: langley
  Unexpected output when searching for a string from os.popen output FujiJean 3 877 Oct-02-2018, 11:39 AM
Last Post: volcano63
  Unexpected twice output Samo 3 771 Sep-29-2018, 10:00 PM
Last Post: Samo
  Unexpected simpy simulation output bakas 1 1,755 Sep-07-2018, 01:14 AM
Last Post: scidam
  unexpected output for global variable bhdebasish 1 764 Aug-22-2018, 04:55 PM
Last Post: Larz60+
  A little unexpected output from a while loop linuxnoob 3 852 Jul-17-2018, 01:02 AM
Last Post: gontajones
  Unexpected output, TypeError and traceback error fier259 2 1,036 May-06-2018, 10:52 PM
Last Post: fier259

Forum Jump:


Users browsing this thread: 1 Guest(s)