# SOLVEDChecking if number is whole or float?

#### Ludiq

##### Member
Is there any way to check if given number is whole or a float and return true or false and do something in both cases ? I need to make a little android app that is dividing a given number by 5 or 6 then check if the answer is whole or float number and if its whole do something and if its float do something else.

#### FoxyOfJungle

##### Kazan Games
Would it be this?

GML:
``````var number = 3.141592

if (frac(number) > 0)
{
show_debug_message("Is fractional");
}``````

Function:
GML:
``````function is_fractional(number)
{
return frac(number) > 0;
}``````

#### Ludiq

##### Member
Yeah it will do. Now the problem is for example the number is 3121 we divide that by 6 and we get 520,1666666666667 now the program know its float number and I need to convert it to 520(whole number) by subtracting 1 number from the original number which is 3121 then divide by 6 again then check if its float or whole again till the result is 520. I need some kind of loop for that but don't know how to make it.

#### GMWolf

##### aka fel666
Yeah it will do. Now the problem is for example the number is 3121 we divide that by 6 and we get 520,1666666666667 now the program know its float number and I need to convert it to 520(whole number) by subtracting 1 number from the original number which is 3121 then divide by 6 again then check if its float or whole again till the result is 520. I need some kind of loop for that but don't know how to make it.
What is the end goal of the process?
Are you trying to find what number to subtract in order to get 520?
Then that's just fract(3121/6)*6;
Are you trying to get the round number 520?
Then just do floor(3212/6).
 oops forgot the /6

Last edited:

#### Ludiq

##### Member
What is the end goal of the process?
Are you trying to find what number to subtract in order to get 520?
Then that's just fract(3121)*6;
Are you trying to get the round number 520?
Then just do floor(3212/6).
I need to find how many digits I need to go down from 3121 till it gets from 520,1666666666667 to 520 in this case its just 1 digit down from 3121.

#### GMWolf

##### aka fel666
I need to find how many digits I need to go down from 3121 till it gets from 520,1666666666667 to 520 in this case its just 1 digit down from 3121.
Well that would be fract(3121/6)*6.

Assuming that by 520 you mean the nex lowest whole number.
Otherwise do ((3121/6)-520) * 6.

Last edited:

#### TheouAegis

##### Member
if you know it will be divided by 5 OR 6, just do

Code:
``````function nearest_multiple(number, divisor)
{
return number - number div divisor * divisor;
}``````
If you don't know if it will be 5 or 6 for whatever reason and want the one closest to the original

Code:
``````function nearest_multiple(number)
{
var a = number - number div 5 * 5;
var b = number - number div 6 * 6;
return min(a,b);
}``````

number div divisor * divisor will round down to the nearest multiple. Thus number - number div divisor * divisor will tell you how much of a difference that is.

#### Ludiq

##### Member
There is one more problem.I made the apk got it on my phone but when I type in the value and hit ok the text on screen doesnt change. This happened after I changed get_integer to get_integer_async. Before that it worked but when I first started the app it told me the get_integer is depricated and to use the async one. How to make it work again? Here is the create event code:
Broiki = get_integer_async("Products created?", "");
val = floor(Broiki/6);
val2 = frac(Broiki/6)*6;
And here is the draw event:
draw_text(x,y,"Broiki na chovek " + string(val));
draw_text(x+20,y+20, "Broiki za razpredelqne " + string(val2));

#### TheouAegis

##### Member
Do you have an async event set up? The async event will run when then player closes the get_integer popup. That's the only time Broiki will have a workable value.

#### GMWolf

##### aka fel666
There is one more problem.I made the apk got it on my phone but when I type in the value and hit ok the text on screen doesnt change. This happened after I changed get_integer to get_integer_async. Before that it worked but when I first started the app it told me the get_integer is depricated and to use the async one. How to make it work again? Here is the create event code:
Broiki = get_integer_async("Products created?", "");
val = floor(Broiki/6);
val2 = frac(Broiki/6)*6;
And here is the draw event:
draw_text(x,y,"Broiki na chovek " + string(val));
draw_text(x+20,y+20, "Broiki za razpredelqne " + string(val2));
please see thew manual entry for With any such things, your first resort should be the manual.

but best you make a separate topic for a separate issue.

#### Ludiq

##### Member
please see thew manual entry for With any such things, your first resort should be the manual.

but best you make a separate topic for a separate issue.
I have already seen the manual entry for it but I dont understand it thats why im writing here.

#### Ludiq

##### Member
Do you have an async event set up? The async event will run when then player closes the get_integer popup. That's the only time Broiki will have a workable value.
No, I dont know how to use it which option to choose and what to put in there.

#### Ludiq

##### Member
New thread it is then. Close this one please!

#### Xer0botXer0

##### Senpai
GML:
``````var check = round(num);

if check == num {whole = true;}``````