Format Django numeric fields in template

0

I receive in my templates some numerical data from a view, for example a salary for this practical case 100,000:

<td>{{ role.salary }}</td>

But in the tenplate he shows it to me with x decimals:

  

100000,33333333

How can I format for example 2 decimals or no decimal in the template?

Thanks in advance.

    
asked by jsanchezs 06.02.2018 в 20:54
source

2 answers

3

I found the form, using a template filter and defining the number of decimals:

{{ role.salary|floatformat:2 }}
    
answered by 06.02.2018 / 21:09
source
0

I would put this as a comment, but I do not have enough reputation ... Also consider using the humanize django filters. You have location options to use the appropriate numeric format in each country and more functionality to format numbers

    
answered by 16.02.2018 в 20:43