The Twig documentation for number rounding talks about rounding decimals, but I have a case where I want to round a number like 19,995 to 20,000. Is there a tricky way to round up to nearest thousand?
Asked
Active
Viewed 1,177 times
2 Answers
3
The simplest way is to divide your original number, round, then multiply again by 1000:
{% set amount = (19995 / 1000)|round %}
{{ amount * 1000 }}
Rounding to the nearest 10k or 100k would be as simple as changing 1000 to 10000 or 100000 respectively.
UPDATE: Or you can just use Matt Rose's suggestion below.
{{ 19995|round(-3) }}

tmirks
- 503
- 5
- 11
-
the separation of content and logic here is the best thing I've ever seen. – ArleyM Nov 13 '15 at 16:46