+1
Answered

Can you round a numerical value as part of an [eval:] statement?

thillsman 12 ár síðan Uppfært 12 ár síðan 4
I've got an app the calculates a number, but it will often get a number like 1807.1428571429, etc. Is there a way to tell the [eval:] statement to 2 decimal places (or even to 0)?
I believe this will work:

For 0 decimals:

[eval:Math.round(2.3333333333)]

For 2 decimals:
[eval:Math.round(2.3333333*100.0)/100.0]
I tried that, but it game me "NaN" as the output. Here's my code:

[eval:Math.round(135.3-(30.8*[var:age])+([var:activity]*(10*[var:weight]+934*[var:height]))+25+' calories')]
I think your problem is with adding 'calories' inside the eval statement. try putting that on the outside.
Of course. Duh, Tyler.

Thanks, Ian!