Rounding to the nearest hundredth
How would I round a value to the nearest hundredth.
How would I round a value to the nearest hundredth.
Below 5 it is a lower number for example 34 would be 30 not 40 if it is 5 and up it will become 40 not 30
// round number to given decimals
// use negative value to round to tens (-1) or hundreds (-2)
roundDec = function(num, decimals=2)
return round(num * 10^decimals ) / 10^decimals
end
// Examples
print(roundDec(PI, 2)) // = 3.14
print(roundDec(145, -1)) // = 150
print(roundDec(145, -2)) // = 100
Or do it hard coded:
value = 245
round(value/100)*100 // returns 200
round(value/10)*10 // returns 250
thanks!!!