For example
number=10.123456
How do I remove the thousandths of number so that it is only 10.12
? Please help me
For example
number=10.123456
How do I remove the thousandths of number so that it is only 10.12
? Please help me
One possible solution is to create a function for rounding by using the math.floor :
function arredonda(num, numCasasDecimais)
local mult = 10^(numCasasDecimais or 0)
return math.floor(num * mult + 0.5) / mult
end
After execution:
> a=10.123456
> arredonda(a, 2)
10.12
>
The above function is just an example. For more efficient and / or accurate implementations, refer to the Simple Round
Also try string.format("%.2f",number)
.