Forum

> > CS2D > Scripts > Rounding Off With Lua
Forums overviewCS2D overview Scripts overviewLog in to reply

English Rounding Off With Lua

5 replies
To the start Previous 1 Next To the start

old Re: Rounding Off With Lua

Jynxxx
User Off Offline

Quote
I like to use this function
1
2
3
function round(num, idp)
	return tonumber(string.format("%." .. (idp or 0) .. "f", num))
end

So you would use it like...
1
round((75.65*8), 2)
2 = the number behind the decimal.
Also check out this link, would most likely help you. Simple Rounding

old Re: Rounding Off With Lua

EP
User Off Offline

Quote
Well, I declare this function the most basic round system.

1
2
3
function math.round(n)
	return math.floor(n+.5)
end

Good luck

old Re: Rounding Off With Lua

Infinite Rain
Reviewer Off Offline

Quote
Here's the code, which noob scripters like me would use:
1
2
3
function roundup(x)
	return math.floor(x + 0.5)
end

Edit:
Ugh, I'm way too late
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview