Skip to main content

Hello,

How can I remove the ".0" decimal if the numeric value is a whole number, so it reads "$16" instead of "$16.0"? However, if the numeric value includes decimals, like "$16.29", it should remain as is without rounding or removing the ".29" decimal.

Thank you!
 

 

Hi @Joselito

Thanks for being a part of our community! In django templates, the floatformat filter is used to control the number of decimal places displayed. floatformat will round the number to the specified decimal places, and it will only display decimal places if they are non-zero.

To round a decimal number but display it as an integer if it ends in .00, you would use floatformat with a negative value. For example:

{{ value|floatformat:"-2" }} . This will round the number to two decimal places. However, if the number ends in .00, it will be displayed as an integer without any decimal places. I hope this helps!

~Chloe


Reply