- Joined
- Dec 19, 2007
- Messages
- 1,234
Math (real rounded upward) -> is there a base function to do it?
Set Decimals = RealNum - Integer(RealNum)
If Decimals > 0.5 then
set RealNum = Integer(RealNum) + 1
else
set RealNum = Integer(RealNum)
you could just skip all that hassle and use:
- set integervariable = (integer((realvariable + 0.50)))
Edit:
approved, but it will work only if you use 0.99 and not 0.5:
Real =0.99, need to bring it to int upward
0.99 + 0.99 =1.98 (int 1)
Real =0.01, need to bring it to int upward
0.01 + 0.99 = 1.00 (int 1)
set integervariable = (integer((realvariable + 0.99)))
Decimals is not a function, I used that way also, my main quesion was if there was based function to make it use less functions.
nice try though
Incorrect, it will convert 0.001 wrongly.Adding 0.99 to the real will change it into a ceiling function.
Yeah but it is practical.Incorrect, it will convert 0.001 wrongly.
Decimals is a variable representing the remainder of the number after its integer has been chopped off.
Yeah, true.
By default, wc3 floors the real numbers when converting to integers.
Adding 0.50 to the real will change it into a rounding function.
Adding 0.99 to the real will change it into a ceiling function.
Probably the best way to do it when you are facing reals who can become more precise than 0.01.Yeah but it is practical.
Sure you could just go all:
If (realVar mod 1) not equal to 0, then intVar = integer(realVar+1), else intVar = integer(realVar)If you really need it to be that accurate.