On Sep 17, 2007, at 9:18 PM, johnf wrote:
> I have to add some dollars and cents and display the total in a
> textbox. The
> issue is it is displaying a number with several ending zero's.
> 1.01 + 2.02 = 3.030000
That's because you're using floats. There is no way to represent
many floating numbers exactly in a binary system.
> Is there a simple way of changing the display to only '3.03'?
Two choices: use the decimal module, or use string formatting:
x = 1.01 + 2.02
x
-> 3.0300000000000002
print "%.2f" % x
-> '3.03'
-- Ed Leafe
-- http://leafe.com
-- http://dabodev.com
_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-users
Searchable Archives: http://leafe.com/archives/search/dabo-users
This message: http://leafe.com/archives/byMID/dabo-users/[EMAIL PROTECTED]