KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Utility method for getting the ceiling of a real number
PRODUCT: 4D | VERSION: 13.2 | PLATFORM: Mac & Win
Published On: April 19, 2013

This Technical Tip provides a utility method that returns the ceiling of a real number.

// ----------------------------------------------------
// Method: math_ceiling
// Description
// Returns the ceiling of a given real number
// Parameters
// $1 (Real) - Number
// ----------------------------------------------------
C_REAL($1;$num_l)
C_REAL($numTruc_l)
C_REAL($0)

$num_l:=$1
$numTruc_l:=Trunc($num_l;0)

If (($num_l-$numTruc_l)#0)
   $0:=$numTruc_l+1
Else
   $0:=$numTruc_l
End if


Below are examples of the method:

$result:=math_ceiling (1)     //$result  =  1
$result1:=math_ceiling (0.6)  //$result1 =  1
$result2:=math_ceiling (1.4)  //$result2 =  2
$result3:=math_ceiling (5.1)  //$result3 =  6
$result4:=math_ceiling (-5.1) //$result4 =-5
$result5:=math_ceiling (-0.1) //$result5 = 0