# Detecting if Real is an Integer

#### Tawnttoo

##### New Member
The title may be misleading but what I need is a way to check if a real is in this form: X.00 as in a whole number?

if (real to int( REAL ) ) is equal to REAL

real to integer always rounds down. no matter what values follow the floating point. 7.1 and 7.99 both are 7 if converted into an integer.

But if I'm using a 0.05 second interval and reduce a real bu 0.05 each time, how can I check if it is a whole number?

the way i just posted above. what is the problem?

I think so. Because what your method would do is once the .05 makes, say, 6 fall below 6.00 to 5.95 it would automatically reduce it to 5.00 which isn't what he wants. What I see is he wants it to tell him once the number becomes a whole number like so:

Each line is after every x seconds.
6.00 true
5.50 false
5.40 false
5.30 false
...
...
5.10 false
5.00 true
4.90 false

and so on.

Just transform into a integer your real and then sustract, if it is equal to 0 then your number is a integer, if not, its a real. Example:
5 is the integer of that real
5.0-5 = 0
So your real is an integer.

Other
5 is the integer part of that real
5.5-5 = 0.5 , so your real isnt a integer.

Just transform into a integer your real and then sustract, if it is equal to 0 then your number is a integer, if not, its a real. Example:
5 is the integer of that real
5.0-5 = 0
So your real is an integer.

Other
5 is the integer part of that real
5.5-5 = 0.5 , so your real isnt a integer.

Just as a hint: to do this in GUI you should use "Convert Real to Integer".

The check will be something like this:
Code:
``YOURNUMBER - (convertToReal (convertToInt ( YOURNUMBER ) )) == 0``

There's no need to subtract. Just compare the value to the original real, rather than subtracting and comparing to 0.

I think so. Because what your method would do is once the .05 makes, say, 6 fall below 6.00 to 5.95 it would automatically reduce it to 5.00 which isn't what he wants. What I see is he wants it to tell him once the number becomes a whole number like so:

Each line is after every x seconds.
6.00 true
5.50 false
5.40 false
5.30 false
...
...
5.10 false
5.00 true
4.90 false

and so on.

maybe i should give some examples to clarify:

lets look at this:
if (real to int( REAL ) ) is equal to REAL

lets say our value REAL is 6.00
we check
if (real to int(6.00) == 6.00) => if (6 == 6.00) => true

we substract 0.25 and check:
if (real to int (5.75) == 5.75) => if (5 == 5.75) => false

we substract 0.25 and check:
if (real to int (5.5) == 5.5) => if (5 == 5.5) => false

we substract 0.25 and check:
if (real to int (5.25) == 5.25) => if (5 == 5.25) => false

we substract 0.25 and check:
if (real to int (5.0) == 5.0) => if (5 == 5.00) => true

we substract 0.25 and check:
if (real to int (4.75) == 4.75) => if (4 == 4.75) => false

... and so on and so on...

that means we will get TRUE whenever REAL is a whole number like 1.00, 2.00, 3.00, 4.00, and so on.
We will get FALSE whenever there are other digits then 0 after the floating point. for example 5.47 because (5 != 5.47)

So, if I'm using the 0.05-second-interval trigger for 20 seconds, do I have to check if its 20.00, 19.00, 18.00 etc in conditions? Using 'Or-multiple conditions'?

no, you just do the following:
(written in pseudo code)

Code:
``````MyReal = 20

loop do
MyReal -= 0.05
if (MyReal.to_int) == MyReal
comment: ITS AN INTEGER! HURRAY!
else
comment: ITS NOT AN INTEGER.....
end
end``````

I have this:

Trigger:
• Game - Display to (All players) the text: ((String((Load (Key duration) of (Key (Picked unit)) from Surge_Hash))) + ( not equal to + (String((Integer((Load (Key duration) of (Key (Picked unit)) from Rune_Hash)))))))

It always shows the integer as 0.

JASS:
``````function RqI takes real A returns boolean
return A - R2I(A) != 0.0
endfunction``````

special note, equal comparison WILL NOT WORK in this case.

JASS:
``````        if RqI(6.0) then
call BJDebugMsg(&quot;true!&quot;)
else
call BJDebugMsg(&quot;false!&quot;)
endif``````

Obiusly it shows false cuz the result is 0 == 0.0

Other thing,
Logicaly, A - R2I(A) == 0.0 is the same as A == R2I(A)

equal comparison will fail, it will count 6.001 and 6.002 as same reals, but this is not true.

with not equal it will detect fine.

did you tested?
anyways we are comparing with the integer part I dont see your point

For some reason, it sets it to an integer below when it hits a whole number. E.g. 18.00 ---> 17

EDIT: got it to work by adding 1 to the integer. Thanks for the help!

The [LJASS]ModuloReal[/LJASS] function may interest you. See also [LJASS]ModuloInteger[/LJASS]. If I wanted to see if an integer was a multiple of 10...

JASS:
``````if ModuloInteger(i, 10) == 0 then
// i is divisible by 10... some examples of i would be -50, 60, or even 0.
endif``````

General chit-chat
Help Users
• No one is chatting at the moment.
• The Helper:
https://www.thehelper.net/pages/news/ is a link to the old news portal - i will integrate it into the interface somewhere when i figure it out
• Ghan:
Need to try something
• Ghan:
Hopefully this won't cause problems.
• Ghan:
Hmm
• Ghan:
I have converted the Headline News forum to an Article type forum. It will now show the top 20 threads with more detail of each thread.
• Ghan:
See how we like that.
• The Helper:
I do not see a way to go past the 1st page of posts on the forum though
• The Helper:
It is OK though for the main page to open up on the forum in the view it was before. As long as the portal has its own URL so it can be viewed that way I do want to try it as a regular forum view for a while
• Ghan:
Yeah I'm not sure what the deal is with the pagination.
• Ghan:
It SHOULD be there so I think it might just be an artifact of having an older style.
• Ghan:
I switched it to a "Standard" article forum. This will show the thread list like normal, but the threads themselves will have the first post set up above the rest of the "comments"
• The Helper:
I don't really get that article forum but I think it is because I have never really seen it used on a multi post thread
• Ghan:
RpNation makes more use of it right now as an example: https://www.rpnation.com/news/
• The Helper:
• The Helper:
What do you think Tom?
• tom_mai78101:
I will have to get used to this.
• tom_mai78101:
The latest news feed looks good
• The Helper:
I would like to see it again like Ghan had it the first time with pagination though - without the pagination that view will not work but with pagination it just might...
• The Helper:
This drink recipe I have had more than a few times back in the day! Mind Eraser https://www.thehelper.net/threads/cocktail-mind-eraser.194720/
• The Helper:
Happy Thursday!
• Ghan:
I'm not so sure, there's still a lot of Thursday left for it to become unhappy.
+3
• The Helper:
still a few hours
• The Helper:
Its Friday!!!!
+1
• Ghan:
Thursday 7/10 would Thursday again
+3

### Members online

No members online now.