How can I control the formatting of numbers in Jade template?
Sample code:
for item in issue.item
tr
td.utilityValue #{item.$.value}
td.utilityUtil #{item.$.evaluation * utilitySpace.weightmultiplyer}
I want the numbers to print with 2 significant digits.
Here is the solution I found; it works for Express 3:
Install sprintf by issuing:
npm install sprintf
In app.js:
app.locals.sprintf = require('sprintf').sprintf;
app.locals.format = "%+1.0f";
In template.jade:
...... td.utility #{sprintf(format, value)} ......
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With