5
Contributors
5
Replies
6
Views
6 Years
Discussion Span
Last Post by knan
Featured Replies
  • 1

    Well a simple fix would be to multiply everything by 10. Ie: [CODE]import os print float(1+1+1-3)/10 os.system("pause")[/CODE] Read More

  • 1

    To be at sure side add in beginning of your numeric Python 2 code: [CODE]from __future__ import division[/CODE] This makes 1/4 produce 0.25, not 0 (integer division). For integer division use // operator. Read More

  • Start with this documentation page [url]http://docs.python.org/tutorial/floatingpoint.html[/url]. A problem is that python's 0.1 is not the mathematical 0.1 because 0.1 can not be represented exactly as a machine binary number. Read More

  • 1

    The limits of floating point numbers [url]http://www.lahey.com/float.htm[/url] [url]http://docs.python.org/tutorial/floatingpoint.html[/url] Use decimal for more precision. [CODE]from decimal import Decimal as dec # 0.1 + 0.1 + 0.1 - 0.3 = 0.0 x = dec("0.1") y = dec("0.3") print x + x + x - y [/CODE] Read More

1

Well a simple fix would be to multiply everything by 10. Ie:

import os
print float(1+1+1-3)/10
os.system("pause")
1

To be at sure side add in beginning of your numeric Python 2 code:

from __future__ import division

This makes 1/4 produce 0.25, not 0 (integer division). For integer division use // operator.

0

Thank you very much everyone... Now i understand the reason behind it... Thank you!

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.