Forum

> > CS2D > Scripts > Full Number
Forums overviewCS2D overview Scripts overviewLog in to reply

English Full Number

4 replies
To the start Previous 1 Next To the start

old Full Number

Temper
User Off Offline

Quote
umm i just want to know some stuff, how can i do like a function like
fullnumber(1.374)
it will return false because it isnt a full number
and how can i make another function turning it to a full number ?
Thanks.
edited 1×, last 26.03.12 07:16:36 am

old Re: Full Number

Apache uwu
User Off Offline

Quote
Either math.floor or math.ceil.

1
2
3
4
local myNumber=1.374
local rounded=math.floor(myNumber)
print(myNumber)
print(rounded)

Prints: 1.374
      1

Edit:

1
2
3
4
5
6
7
function fullnumber(number)
	return number==math.floor(number)
end

function makefullnumber(number)
	return math.floor(number)
end
edited 1×, last 26.03.12 07:31:07 am

old Re: Full Number

ohaz
User Off Offline

Quote
1
2
3
if (myNumber == math.floor(myNumber) then
...
end

old Re: Full Number

Flacko
User Off Offline

Quote
There are probably a few dozens of way to achieve that,
I'd use:
1
2
3
if myNumber%1 == 0 then
	--full number
end

old Re: Full Number

Apache uwu
User Off Offline

Quote
Ah! The modulo % operator, totally forgot about that. In terms of speed, that uses less cpu rounds and is faster √
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview