round() function

mailing list ivan.python1 at gmail.com
Thu Feb 25 16:45:37 CET 2010


On 25.2.2010. 16:39, Tracubik wrote:
> 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?
>
> Thanks in advance
> Nico
>    
You may wanna use string formating, e.g.: print "%.2f" % 4.5



More information about the Python-list mailing list