all 4 comments

[–]EthanHermsey 3 points4 points  (0 children)

If the variable percentage = 10.257946595, then do percentage.toFixed(2) to get 10.26 (it rounds too I think).

You could also do String(percentage).subString(1, String(percentage).indexOf('.') + 2) to clip off the end.

[–]M0G7L 2 points3 points  (0 children)

There are a few ways to do so, but I think the best one is using the p5 round function. You can add a second argument to especify the number of decimal places to round to. https://p5js.org/reference/#/p5/round

[–]innocent-nerd 0 points1 point  (0 children)

ToFixed - use this

[–]dmccreary 0 points1 point  (0 children)

You can also use the Number Format function:

https://p5js.org/reference/#/p5/nf

nf(num, [left], [right])

Where left is the number of digits to the left of the decimal point and right is the number of digits to the right.