3

I have in my database the values a, b, and c, as example. Now i need to format theses values to a1, b1 and c1.

a)  2000000000
a1) 20,000,000.00

b)  300000
b1) 3,000.00

c)  30000
c1) 300.00

I tried this:

'{:20,.2f}'.format(30000) # 30,000.00 and i need 300.00
'{:20,.2f}'.format(300000) # 300,000.00 and i need 3,000.00
...

So, what i am trying is not working as expected. Anyone has an idea how can achieve the format that i am looking for?

anvd
  • 3,953
  • 16
  • 60
  • 119
  • 1
    Don't you mean `'{:20,.2f}'.format(30000/100.)`? This isn't really a *programming* problem, so much a *thinking* problem. – jonrsharpe Aug 13 '15 at 09:16

1 Answers1

5

You're passing in integers but you want to display floating point numbers.

You could fix this by passing floats or by dividing by the number of decimal points

'{:20,.2f}'.format(30000/100.0)
jonrsharpe
  • 107,083
  • 22
  • 201
  • 376
muddyfish
  • 3,161
  • 28
  • 35