How do I remove the thousandths of a value?

2

For example

number=10.123456

How do I remove the thousandths of number so that it is only 10.12 ? Please help me

    
asked by anonymous 02.01.2017 / 21:32

2 answers

2

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

    
03.01.2017 / 00:56
3

Also try string.format("%.2f",number) .

    
05.01.2017 / 01:00