Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to round in Jade?

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.

like image 847
Vico Avatar asked Jan 08 '14 22:01

Vico


2 Answers

Jade 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 comment, the syntax is standard JavaScript as described here

like image 130
Jason Nichols Avatar answered Oct 31 '22 15:10

Jason Nichols


.toFixed() may also be useful for showing 'clean' numbers: http://www.w3schools.com/jsref/jsref_tofixed.asp

like image 6
Chris Avatar answered Oct 31 '22 14:10

Chris