How to get around problems with Ceil()
Author: | cake
|
Submitted: | 6th December, 2003
|
Views: | 4728
| Rated: |
|
|
If you have ever had trouble with MMF and decimal places, no doubt you would consider it an extremely frustrating thing when you tell MMF to set a counter to Ceil(1/5) only to see it sets it to 0. VERY annoying.
This article will show you how to Ceil, using the Immediate If Object.
Ok, if you haven't used IIF Object before, this is going to look very confusing, my suggestion is go and read how to use IIF if this is too complicated at first glance. I'll write it as it appears in MMF and also in pseudocode so you can easily see the nested IF statement.
Ceil
Key: Num = Numerator, Den = Denominator
MMF Style-
Set value A to CompareIntegers(IIF, Den, =, 0, 0, CompareIntegers(IIF, Num mod Den, =, 0, Int(Num/Den), Int(Num/Den) + 1))
Pseudocode-
IF Den = 0 THEN
value A = 0
ELSE
IF Num mod Den = 0 THEN
value A = Int(Num/Den)
ELSE
value A = Int(Num/Den) + 1
ENDIF
ENDIF
|
|
cake
Registered 13/12/2002
Points 1173
|