Javascript(let)? to round variable to 2 decimal places

192 views
Skip to first unread message

Richard Wallace

unread,
Jan 5, 2015, 1:38:59 PM1/5/15
to tas...@googlegroups.com
Anyone know how to do this?
Anything I've found via google doesnt work.
I have a variable, %var = 24.459
I want it round to too 2 decimal points.
So it should = 24.46

I've seen that Java can do this but haven't been able to get it too work?

easiuser

unread,
Jan 5, 2015, 3:50:59 PM1/5/15
to tas...@googlegroups.com
Tasker variables are passed to JavaScript as a string.  Also JavaScript uses Tasker variables without the % sign and var is a keyword in JavaScript.  Create a variable %taskervar = 24.4569 then run this script.

taskervar = parseFloat(taskervar).toFixed(2);

Alternatively in Tasker you could do this:

Variable Set %var to round(%var*100)/100

Jeremy Harris

unread,
Jan 5, 2015, 4:34:17 PM1/5/15
to tas...@googlegroups.com
I'm just learning, but I'm working with a JavaScript that rounds numbers by calling Math.round() function. I don't see it described in the library of .js files, so it might be built in?

I did the following in a mixed java/html document:

tk.setLocal("taskerVarName", Math.round(var))

SportyRydr

unread,
Oct 25, 2015, 7:42:05 PM10/25/15
to Tasker

Thanks you!!
Reply all
Reply to author
Forward
0 new messages