There isn't a super nice way to do this in Lua, unfortunately.
Here are two options. One based on processing the number as a number, the other by processing the number as a string.
Math
We can use modulus to find the thousandths+ part of the number, and remove that. If we want to round rather than truncate, we would add five thousandths to the number before doing this:
1 | function truncate(x, places) |
2 | return x - x % 10 ^(-places) |
5 | function round(x, places) |
6 | return truncate(x + 10 ^ (-places) / 2 , places) |
Strings
We can turn the number into a string, then chop off the places too many after the decimal point. This can't (easily), only truncate.
2 | x = x:gsub( "%.(%d%d)%d+" , ".%1" ); |
A cool property of the second one is that you can use it on full segments of text, not just the number itself.