Todd Reed
May 1st, 2006, 08:35 PM
I was struggling with a simple decimal rounding issue and found this code snippet.
function round (n,shift)
shift = 10^shift
return math.floor ((n*shift)+0.5)/shift
end
simple call it with your value...
a = round (1234.567, 0) -- gives "1235"
a = round (1234.567, 1) -- gives "1234.6"
a = round (1234.567, -2) -- gives "1200"
Hope this helps others... :D
function round (n,shift)
shift = 10^shift
return math.floor ((n*shift)+0.5)/shift
end
simple call it with your value...
a = round (1234.567, 0) -- gives "1235"
a = round (1234.567, 1) -- gives "1234.6"
a = round (1234.567, -2) -- gives "1200"
Hope this helps others... :D