Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get a decimal field to show more decimal places in a template?

price_a = models.DecimalField(max_digits=5, decimal_places=3) 

Example price: 95,90

In my template:

{{ price_a }} 

it display only 95,9. How can I get it to display full price (with an extra trailing 0: 95,90)?

like image 550
user1745580 Avatar asked Oct 15 '12 20:10

user1745580


People also ask

How do I get Excel to display more decimal places?

Select the cells you want to format. On the Home tab, select Increase Decimal or Decrease Decimal to show more or fewer digits after the decimal point. Each selection or click adds or removes a decimal place. Your new decimal places setting is now in effect.

How do you set a Fields decimal place property in design view?

Press TAB, open the drop-down menu, and choose Number. Click in the Field Size property, open the drop-down menu, and choose Single. Press TAB, open the drop-down menu, and choose Fixed. Click in the Decimal Places property.


1 Answers

Use the floatformat template filter, for example

{{ price_a|floatformat:2 }} 
like image 177
Alasdair Avatar answered Oct 01 '22 05:10

Alasdair