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