fp_rnd
Previous Topic  Next Topic 

Synopsis:

       answer = fp_rnd(number, type, digit[, decimals])

Arguments:

       number - The number to round

       type - How to round (0=Truncate, 1=Round up, 2=Round nearest)

       Digit - The digit position to round (+ for before decimal place, - for after decimal place)

       [decimals] - Optional argument to specify the number of decimal places of the returned result


Description:    This function allows for a floating point number to be rounded to a certain number of places.    The number can be rounded up, down or truncated depending on the value specified in the type argument.         Type can be specified as one of the following:


0        truncate (or round down)

1        round up

2        round up or down based on whether the least significant digit is less than or greater than 5.


The digit argument specifies the digit position to round to.    If a positive value is given for digit then this specifies a digit position to the left of the decimal place.   For example using the type truncate :


         fp_rnd("1234.567",0,3)   returns  "1000.000"

         fp_rnd("1234.567",0,2)   returns  "1200.000"

         fp_rnd("1234.567",0,1)   returns  "1230.000"


If a negative value is given for digit then this specifies a digit position to the right of the decimal place:


         fp_rnd("1234.567",0,-3)   returns  "1234.567"

         fp_rnd("1234.567",0,-2)   returns  "1234.560"

         fp_rnd("1234.567",0,-1)   returns  "1234.500"


This function has an optional additional argument specifying the number of decimal places used for rounding. The initial default number of decimal places used for rounding is 2, this default value may be changed by calling fp_decs(n) where n is 0 to 9 specifying the number of decimal places. The current default is over-ridden by specifying an explicit number of decimals.


Returns:  Returns the number rounded as specified.