round off to two decimal & return float
Roland Mueller
roland.em0001 at googlemail.com
Sat Mar 30 05:28:41 EDT 2013
Hello,
2013/3/30 ஆமாச்சு <amachu at amachu.me>
> Consider the scenario,
>
> >> a = 10
> >> "{0:.2f}".format(a)
> '10.00'
>
> This returns a string 10.00. But what is the preferred method to retain
> 10.0 (float) as 10.00 (float)?
>
> I assume you have a numeric value a and want to have a float with 2
decimals. This can be achieved with the function round():
>>> a = 10
>>> type(a)
<type 'int'>
>>> a = round(10,2)
>>> type (a)
<type 'float'>
>>> a
10.0
BR,
Roland
> I am trying to assign the value to a cell of a spreadsheet, using
> python-xlwt. I would like to have 10.00 as the value that is right
> aligned. With text it is left aligned.
>
> --
>
> Sri Ramadoss M
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20130330/da0f3b18/attachment.html>
More information about the Python-list
mailing list