Trouble with decimals


#1

I’m trying to figure out how to add 0.1 to a number, I can add 0.0 + 0.1 = 0.1 and then 0.1+0.1= 0.2 but then when I get to 0.2+0.1 =.3000000000004 and then the next addition maybe correct and after that, the next set would be off and then everything is off from there.


#2

Hi!

That is annoying behavior! You can use the toFixed() function on the result to guarantee a certain number of decimal places. E.g., for one decimal place:

Set text on (label) to [[ (Target.text + 0.1).toFixed(1) ]]

#3

I have tried the .toFixed as well and still the same issue. I have tried a few different values,

  1. [[var1+0.1]]
  2. [[var1+0.1.toFixed(1)]]
  3. [[var1+1/10.toFixed(1)]]

#4

[[(var1+0.1).toFixed(1)]] solved the issue.

Thanks for all your help


#5

More info if you’re interested: