round() function

Stefan Behnel stefan_ml at behnel.de
Thu Feb 25 10:46:18 EST 2010


Tracubik, 25.02.2010 16:39:
> hi all, i've this sample code:
> 
>>>> n = 4.499
>>>> str(round(n,2))
> '4.5'
> 
> 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?

Format the number as a string:

    print("%.2f" % round(n,2))

Stefan




More information about the Python-list mailing list