Is there any way to round a float to the nearest decimal place in processing?
For example
float x = 1.0000001
float y = 1.1000000001
float a = x + y
round(a)
a = 2.10
The standard round() in processing rounds to the nearest whole number, but I need to have the decimals in place. I can’t find a function that does what I’m looking for. I have some floats with over a hundred decimal places so I need to trim them down, if its possible.
Here is a function that is more processing-centric:
and to test it:
this is probably not the most efficient algorithm, but it works.