最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Is it possible to round in Jade? - Stack Overflow

programmeradmin5浏览0评论

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
Add a ment  | 

2 Answers 2

Reset to default 8

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 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

发布评论

评论列表(0)

  1. 暂无评论