1. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Nov 2012
Posts
3
Rep Power
0

Im using Python 3

How can I get a float, say 1.0 to print 1.00?
My goal is to make it look like dollars and cents.
2. No Profile Picture
Contributing User
Devshed Newbie (0 - 499 posts)

Join Date
Jul 2007
Location
Joensuu, Finland
Posts
471
Rep Power
70
Originally Posted by looptyloop
How can I get a float, say 1.0 to print 1.00?
My goal is to make it look like dollars and cents.
Code:
```>>> amount = 1
>>> print('{0:.2f}'.format(amount))
1.00```
3. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Nov 2012
Posts
3
Rep Power
0
Originally Posted by SuperOscar
Code:
```>>> amount = 1
>>> print('{0:.2f}'.format(amount))
1.00```
format! thanx a bunch. Worked like a charm.

Can you tell me how it works?
The .2 is for two digits to the right.
What is the 0 and f for? and is there other ways to do this?
4. No Profile Picture
Contributing User
Devshed Newbie (0 - 499 posts)

Join Date
Jul 2007
Location
Joensuu, Finland
Posts
471
Rep Power
70
Originally Posted by looptyloop
Can you tell me how it works?
The .2 is for two digits to the right.
What is the 0 and f for? and is there other ways to do this?
0 stands for the first argument in the .format() list, since counting always starts from 0 in Python, and “f” stands for “float”, since that’s how we want that argument to be interpreted.

For further information, you’d better start from the appropriate section in the Python tutorial .
5. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Nov 2012
Posts
3
Rep Power
0
Originally Posted by SuperOscar
0 stands for the first argument in the .format() list, since counting always starts from 0 in Python, and “f” stands for “float”, since that’s how we want that argument to be interpreted.

For further information, you’d better start from address the appropriate section in the Python tutorial .
thankyou