Devin B.
Devin B.

Reputation: 453

Check/verify if in Django template, there are real numbers in decimal places, and if zeros, round off

I couldn't seem to find a specific answer for this question. So, my question differs based on two different scenarios:

(1) In my Django template, can I use some kind of filter to round real numbers in the decimal position, to only 2 digits, but still round any zeros to the nearest whole number/integer? (ie $1.25 and 1.00 would look like $1.25 and $1 respectively)

** Unfortunately, |floatformat:2 includes the zeros

(2) If the above is not possible, is there some kind of conditional where I can check beforehand in the Django template if there are real numbers in the decimal position instead of zeros, and perform some kind of logic as a result?

Thanks in advance!

Upvotes: 1

Views: 1403

Answers (1)

Thomas John
Thomas John

Reputation: 2188

Use django template tags if you need any custom operation to be done in Django.

OR

{{ value|floatformat:"-2" }} this may work in your case

Upvotes: 2

Related Questions