• Math.Round fail: I need to round to a decimal place
    3 replies, posted
So, yeah. I need to round to a number about 2 or three decimal places (i'm working with CurTime(), which spews out a huge string of numbers, and comparing it to another CurTime(): inconsistencies mean they never match). Math.Round is too simple, since i'm working a window of .45. Any suggestions?
Very old thread, but it helps you with your problem. [url]http://www.facepunch.com/showthread.php?t=249562[/url]
Multiply by x. Math.Round it. Divide by x. (Where x is an exponent of 10. i.e. 10, 100, 1000, etc.)
[lua] function math.floor10(number, digits) return math.floor(number*10^digits)/10^digits end function math.round10(number, digits) return math.floor(number*10^digits+0.5)/10^digits end [/lua]
Sorry, you need to Log In to post a reply to this thread.