|
| 31 Mar 2014 11:52 AM |
I made my own rounding function after finding out Lua only has math.floor and math.ceil
Here is the function with some example code for you to test it with idk
function round(num, idp) local mult = 10^(idp or 0) return math.floor(num * mult + 0.5) / mult end
round_nums = { round(0.9345, 3); --> 0.935 round(0.2); --> 0 round(0.49); --> 0 round(0.5); --> 1 }
for k,v in pairs(round_nums) do print(v) end print("end of test") |
|
|
| Report Abuse |
|
suremark
|
  |
| Joined: 13 Nov 2007 |
| Total Posts: 6315 |
|
|
| 31 Mar 2014 05:13 PM |
Funny, yours looks very similar to mine:
function roundf(n, dec) dec = dec and 10^(math.floor(dec + 0.5)) or 1 return math.floor(n * dec + 0.5)/dec end
Anyhow please only post something if it is notable and worthwhile. Anything with less than half an hour of work (let alone five minutes) put into it is just adding to the already-huge spam pile. |
|
|
| Report Abuse |
|