2
For example
number=10.123456
how do I remove the thousandths of number so that it stays just 10.12
?Help me please
2
For example
number=10.123456
how do I remove the thousandths of number so that it stays just 10.12
?Help me please
3
Also try to string.format("%.2f",number)
.
2
One possible solution is to create a rounding function 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, see the reference (in English): Simple Round
Browser other questions tagged lua
You are not signed in. Login or sign up in order to post.