• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[vJASS] Strange Rounding Off Thingy

Status
Not open for further replies.
Level 17
Joined
Feb 11, 2011
Messages
1,860
Hi guys,

I am making a bounty system for someone and I have encountered a strange issue. When I calculate bounty, it gives 299 instead of 300. Here is the code:

JASS:
private function CalculateBounty takes integer level returns real
    return 250.0 * 1.2 * I2R(level)
endfunction
And where it is called:

JASS:
local integer bounty = GetPlayerState(p, PLAYER_STATE_RESOURCE_GOLD) + R2I(CalculateBounty(GetHeroLevel(u)))
Where u is the dying hero and p is the owner of the killing unit.

Any ideas? Thanks!
 
Level 9
Joined
Apr 23, 2011
Messages
460
JASS:
private function CalculateBounty takes integer level returns real
    return 250.0 * 1.2 * I2R(level)
endfunction

Try not to use I2R()

Reals in WC3 is rounded down so try adding 0.5 real to the return.

Please note that Reals in WC3 aren't rounded down when converted to integer. They undergo a process called truncation in which the points after the cutoff (in this case 0, as to insure a whole number) are literally dropped off. The reason that adding .5 works is because anything that is .5 or greater will increase to the next digit and the ending is dropped off from truncation.
 
Status
Not open for further replies.
Top