spamfresser at ch3ka.de
Thu Feb 25 16:51:40 CET 2010
Am 25.02.2010 16:39, schrieb Tracubik:
> hi all, i've this sample code:
>>>> n = 4.499
> that's right, but what i want is '4.50' to be displayed instead of '4.5'.
> Off course i know that 4.5 = 4.50, still i'ld like to have 4.50.
> How can I solve this?
> Thanks in advance
This has nothing to do with round().
round() returns a float, and float(4.50) is 4.5.
You can *print* it as 4.50 using format strings, but the float will
always be 4.5
>>> n = 4.499
>>> print "%.2f" % x
>>> s="%.2f" % round(n,2)
More information about the Python-list