ROUND vs TRUNCATE vs CEIL (php)

Posted by Admin on 01-Feb-2010 15:30

Hello guys,

I need a function similar to CEIL (in PHP) in order to round a number to the next integer (without decimals).

example: 9.99 should be 10

in progress 9.1B the following functions behaves bad for what I need:

round

truncate

both of them return 9.99 instead of 10

example:

DISP TRUNC (3 * 3.33,2).

thanks,

W.

All Replies

Posted by Admin on 01-Feb-2010 15:41

example: 9.33 should be 10

ROUND (9.33 + .5,0)

Posted by Peter Judge on 01-Feb-2010 15:41

I don't believe there's a built-in function, but you can roll your own along the lines of the below, assuming you want 9.0 to remain 9 (and not 10).

Function Ceiling returns int (pdVal as dec):

If trunc(pdVal,0) eq pdVal then

Return int(pdVal).

Else

Return trunk(pdval, 0) + 1.

End function.

-- peter

PS, there's an ABL sub-community that is more targeted for ABL language questions.

Posted by Admin on 02-Feb-2010 07:04

Thanks,

But the function should be:

Function Ceiling returns DECIMAL (pdVal as dec):

  If trunc(pdVal,0) eq pdVal then

   Return (pdVal).

  Else

    Return TRUNC(pdval, 0) + 1.

End function.

I will use it.

bye.

This thread is closed