As the title suggests, I am looking for a way to round in Jade.
I have a variable that looks like this: 9.039444444444445.
Is it possible to output this number as: 9?
Thanks in advance for all those who support me.
As the title suggests, I am looking for a way to round in Jade.
I have a variable that looks like this: 9.039444444444445.
Is it possible to output this number as: 9?
Thanks in advance for all those who support me.
Share Improve this question asked Jan 8, 2014 at 22:59 VicoVico 1,4292 gold badges13 silver badges17 bronze badges 2- 2 Ehm, Jade is a template engine. Isn't Javascript the go-to tool here? Look here: jade-lang./reference/#code – Robert Harvey Commented Jan 8, 2014 at 23:02
- Yep, i know. But its also possible to calculate with Jade. So I thought that also goes round. – Vico Commented Jan 8, 2014 at 23:13
2 Answers
Reset to default 8Jade lets you run unbuffered JavaScript code in the templating engine. Assuming your variable is named number
- number = Math.round(number)
would round number
to the nearest integer as noted in the source at Robert Harvey's ment, the syntax is standard JavaScript as described here
.toFixed()
may also be useful for showing 'clean' numbers: http://www.w3schools./jsref/jsref_tofixed.asp