Decimal formatting

H

Harlin Seritt

Cant believe I have to post this and get help... and can't believe I
couldnt Google it reasonably well enough... I need to take a float
variable and have it display as a string to always have two decimal
places:

12.3333 -> 12.33
1.0 -> 1.00
etc...

Anyone willing to help with this one?

thanks,

Harlin
 
M

mensanator

Cant believe I have to post this and get help... and can't believe I
couldnt Google it reasonably well enough... I need to take a float
variable and have it display as a string to always have two decimal
places:

12.3333 -> 12.33
1.0 -> 1.00
etc...

Anyone willing to help with this one? 1.00



thanks,

Harlin
 
J

J. Clifford Dyer

Cant believe I have to post this and get help... and can't believe I
couldnt Google it reasonably well enough... I need to take a float
variable and have it display as a string to always have two decimal
places:

12.3333 -> 12.33
1.0 -> 1.00
etc...

Anyone willing to help with this one?

thanks,

Harlin

f = 12.333333
i = 10
f_output = "%0.2f" % f
i_output = "%0.2f" % i


Cheers,
Cliff
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,158
Latest member
Vinay_Kumar Nevatia
Top