Arithmetic operators in JADE

陌路散爱 提交于 2019-12-12 11:24:54

问题


I'm using Jade template engine with NOde.js. I have two variables:

a = 0.0378
b = 0.1545

in Jade I do:

- var result = a + b*2

and I get a very strange number when I do #{result}

0.03780.309

It seems to concatenate the numbers as strings. Could someone tell me how can I use arithmetic operators in Jade?

Thanks


回答1:


Are you sure that a (and also b) is a number and not a string?

If it is a string you will need to to convert it to a number via parseFloat:

- var result = parseFloat(a)+parseFloat(b)*2



回答2:


    h2 Jade的 operation
    - var a = 8
    - var b = 2
    p #{+a+b}
    p #{+a-b}
    p #{+a*b}
    p #{+a/b}


来源:https://stackoverflow.com/questions/10368040/arithmetic-operators-in-jade

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!