Tiny function that takes a number (float or int) and returns a string with (maximum) two decimals. For instance:
10 > "10"
20.03 > "20.03"
17.46134 > "17.46"
So not mathematically accurate, but useful under some circumstances...
function twodecimal(_n) -- will accept a number (float or int) -- turn it into a string and return the string with two decimals local _v=split(tostring(_n),".") if #_v==1 then return _v[1] else return (_v[1].."."..sub(_v[2],1,2)) end end |
P#105105 2022-01-14 21:48
[Please log in to post a comment]