Forum
CS2D Scripts Integer and not integerInteger and not integer
6 Antworten 1
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
function check(number) 	if number%1 == 0 then 		return true 	else 		number = math.floor(number) --or math.ceil I guess 		return number 	end end
This ._. ?
you can try checking if it's above or equal to x.5 then math.ceil and if it isn't, then math.floor.
1× editiert, zuletzt 05.03.14 14:01:00
But, how do i check that ?
Thanks everyone !
1× editiert, zuletzt 05.03.14 14:38:25
Maybe this might help you?
@ siuL: Try this:
1
2
3
4
5
6
7
2
3
4
5
6
7
function check(x) 	if math.floor(x)==x then 		return true 	else 		return math.floor(x+0.5) 	end end
Should return true in case of integers.
Rounds up for values >= X.5
Rounds down for values < X.5
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
check = function(n) 	local fl = math.floor(n) 	if fl == n then 		return true 	else 		return ((n - fl >= 0.5) and math.ceil(n) or fl) 	end end
1
2
3
4
2
3
4
function isInteger(n) 	if n==math.floor(n) then return true end 	return math.floor(n+0.5) end
1