Forum




Integer and not integer
6 replies



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.
edited 1×, last 05.03.14 02:01:00 pm

But, how do i check that ?
Thanks everyone !

edited 1×, last 05.03.14 02:38:25 pm
Maybe this might help you?

@

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



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



