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
  Tracing a multiplication table w/ Python trace() NationalRex22 0 65 Jun-11-2019, 03:31 AM
Last Post: NationalRex22
  ValueError: could not convert string to float michaelbs007 1 328 Jun-08-2019, 08:44 PM
Last Post: micseydel
  Help | float to Int in xlrd Vinci141 0 136 May-13-2019, 07:00 AM
Last Post: Vinci141
  Inclusive (closed) range with float numbers mapg 4 206 Apr-27-2019, 09:09 PM
Last Post: Gribouillis
  syntax error near unexpected token btom529 5 267 Apr-21-2019, 09:03 PM
Last Post: btom529
  Getting an unexpected generator object ? mcgrim 19 424 Mar-29-2019, 11:35 AM
Last Post: gontajones
  Dictionary adds an unexpected list erina 1 188 Mar-14-2019, 01:13 PM
Last Post: ichabod801
  unexpected EOF while parsing whatloop 3 412 Mar-09-2019, 06:59 PM
Last Post: whatloop
  Using Decimal Type instead of Float Bytales 1 298 Mar-02-2019, 06:28 PM
Last Post: Bytales
  Unexpected round behavior pythonCoder 1 162 Feb-19-2019, 02:39 PM
Last Post: marienbad

Forum Jump:


Users browsing this thread: 1 Guest(s)