Formatting numbers
Erik Max Francis
max at alcyone.com
Tue May 1 23:11:22 EDT 2001
Daniel Klein wrote:
> This is almost embarrasing to have to ask this but I can't seem to
> find this
> information.
>
> Given an integer, 12345, how to format this to 123.45 ?
I take it the integer represents cents, and you want to print it as
dollars and cents in the usual manner?
>>> print '%.2f' % (float(12345)/100)
123.45
Convert it to floating point, then divide by 100. It's now in dollars.
--
Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
__ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE
/ \ Nothing spoils a confession like repentence.
\__/ Anatole France
Alcyone Systems' Daily Planet / http://www.alcyone.com/planet.html
A new, virtual planet, every day.
More information about the Python-list
mailing list