-2

I'm using Python 3.5. I have a basic operation but I get a wrong result:

def main(argv):
    cms=None
    damin=4.815
    dbmax=4.858
    it=(dbmax-damin)*1000
    print('Damin {0}    Dbmax {1}    IT {2}'.format(damin, dbmax, dbmax-damin))

So the result is:

Damin 4.815    Dbmax 4.858    IT 0.04299999999999926

But I expect this :

Damin 4.815    Dbmax 4.858    IT 0.043
Athanor
  • 855
  • 1
  • 16
  • 34

1 Answers1

0

Reading up on floating point numbers may be worth while: https://docs.python.org/3/tutorial/floatingpoint.html

Not every number can be represented quite so perfectly and programs do there best to use the closest representation possible. Including when interpreting the magic numbers written into the code.

Tim Bender
  • 20,112
  • 2
  • 49
  • 58