rnd()

Function group Execute on client Platform(s)
Number YES All

Syntax

rnd(number,dp)

rnd(number,dp[,asnumber=kfalse])

Description

Rounds a number to a number of decimal places specified in dp and returns the result.

Rounds a number to a number of decimal places specified in dp and returns the result as a string, or a number if asnumber is kTrue.

Note that the return value of rnd() is (by default) a character string. This is the only representation of the returned number guaranteed to hold the result correctly, due to potential floating point inaccuracies.

You need to be careful when comparing the return values of two calls to rnd(), since the return values are character strings, and will be compared as strings.

The optional parameter asnumber allows you to specify that the function should return a Number, rather than a Character value. Note that this may lose some precision if the data type cannot represent the full floating point value.

Example

Calculate lResult as  rnd(2.105693,5)
# returns 2.10569

Calculate lResult as rnd(2.105693,3)
# returns 2.106

Calculate lResult as rnd(0.5,0)
# returns 1