Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Currency with specific format [duplicate]

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?

like image 343
anvd Avatar asked Feb 09 '26 19:02

anvd


1 Answers

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)
like image 111
muddyfish Avatar answered Feb 12 '26 16:02

muddyfish