A
Anders Jansson
Hi all!
I've been searching for a rounding function or some other means to round a
decimal number "to larger", always, but it can't find it.
I have been looking at the Fix(), Int() and CInt() functions, but all of
them behaves in ways making hard to make this happend.
Some examples:
- Int(val) Fix(val) : Truncates, except if val is negative, then they
behave different!
- CInt(val) : quote "CInt function always rounds it to the nearest even
number. For example, 0.5 rounds to 0, and 1.5 rounds to 2." end quote.
So even if I was to add an offset to the val inside the call like
CInt(val + 0.5),
this doesn't do it if val is = 0.499,
CInt(0.499 + 0.5) = 0, since that is the nearest even number!!
What I want is:
zzz = xxx(2,3) : Wanted value is zzz = 3
zzz = xxx(44.9) : Wanted value zzz = 45
zzz = xxx(33.0001) : Wanted value is zzz = 34
zzz = xxx(-33.001) : Wanted value is zzz = 34
Perhaps this could work for possitive values:
val = 99.2
zzz = Abs(Int(-val) ) : zzz = 100
But what about:
val = -99.2
zzz = Abs(Int(-val) ) : zzz = 99
Any suggestions would be great!!
/Thanks
I've been searching for a rounding function or some other means to round a
decimal number "to larger", always, but it can't find it.
I have been looking at the Fix(), Int() and CInt() functions, but all of
them behaves in ways making hard to make this happend.
Some examples:
- Int(val) Fix(val) : Truncates, except if val is negative, then they
behave different!
- CInt(val) : quote "CInt function always rounds it to the nearest even
number. For example, 0.5 rounds to 0, and 1.5 rounds to 2." end quote.
So even if I was to add an offset to the val inside the call like
CInt(val + 0.5),
this doesn't do it if val is = 0.499,
CInt(0.499 + 0.5) = 0, since that is the nearest even number!!
What I want is:
zzz = xxx(2,3) : Wanted value is zzz = 3
zzz = xxx(44.9) : Wanted value zzz = 45
zzz = xxx(33.0001) : Wanted value is zzz = 34
zzz = xxx(-33.001) : Wanted value is zzz = 34
Perhaps this could work for possitive values:
val = 99.2
zzz = Abs(Int(-val) ) : zzz = 100
But what about:
val = -99.2
zzz = Abs(Int(-val) ) : zzz = 99
Any suggestions would be great!!
/Thanks