HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Integer and real

03-04-2008, 08:19 PM#1
SkriK
When i convert a real to integer (in this case unit HP) the integer ends up rounded downwards.

Ex.
Unit HP = 407.275
Real converted to integer = 407
Ingame display = 408

How come they are rounded off differently?
03-04-2008, 08:27 PM#2
Anitarf
They just are. You'd have to ask blizzard why. I imagine the ingame display rounds it to the nearest integer. You could get the same effect with R2I(hp+0.5).
03-04-2008, 08:32 PM#3
SkriK
So no way to get around it?
03-04-2008, 08:58 PM#4
Anitarf
Around what?

Edit: BTW, the system linked to in your signature can no longer be downloaded.
03-04-2008, 09:00 PM#5
SkriK
To get the converted Real-to-integer to match the ingame number.
03-04-2008, 09:01 PM#6
Anitarf
Quote:
Originally Posted by Anitarf
You could get the same effect with R2I(hp+0.5).
This.
03-04-2008, 09:07 PM#7
SkriK
How does it work?
(Yeah yeah i'm stupid)
03-04-2008, 09:11 PM#8
Captain Griffen
Reals converted to integer always rounds down. Always.

Adding 0.5 to the number and THEN rounding it effectively means you round in the normal way.
03-04-2008, 09:14 PM#9
SkriK
Ooooooooooooooohhh, of course! Ty!

Works just fine now, thanks again.
03-04-2008, 09:20 PM#10
Captain Griffen
However, if .275 is rounded up by the game for display purposes, then that wouldn't be quite accurate. Find the lowest decimal that rounds up, then add (1-that decimal) to the real before converting to integer.
03-05-2008, 12:39 AM#11
PipeDream
I think the idea is 0hp displayed means dead. Things like poison will peg you to <1hp, but only 1hp means still alive, so they display that, although this is an oversimplification.