Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove the decimal part of a floating-point number in django?

I have a variable called {{value.item_total }} which is 499.00, but I want to remove the decimal points for this value in my templates file to make it 499. How could I do this?

like image 936
user2169287 Avatar asked Jan 23 '26 17:01

user2169287


2 Answers

Seen here:

You can use the floatformat filter with a negative argument!

The answer would be:

{{ value.item_total|floatformat }}
like image 184
astorije Avatar answered Jan 25 '26 07:01

astorije


you have to use Built-in template tags and filters (https://docs.djangoproject.com/en/1.5/ref/templates/builtins/#get-digit). In your case use

{{ value.item_total|floatformat:"0" }}

Thats it.

Greetings

like image 24
bofh Avatar answered Jan 25 '26 06:01

bofh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!