round$

Syntax

result = ROUND$(number, precision)

Arguments

result: text

number: numeric

precision: integer

Meaning

Returns the value of number rounded off to precision number of decimal points, as a string. The method of rounding is: 5 or more: upwards; below 5: downwards.
If number is an empty value, result will be "0" (instead of the empty string you might expect).
If the rounded off value results in a value that ends with decimal zeros, the zeros won't end up in the resulting string, so if you ask for a precision of 2 and your value rounds off to 7.50, the result string will contain "7.5". If you do want such padding with decimal zeros, you could use a piece of adapl code similar to the following:

 

integer maxOcc, occ text tag[2], integerNumber[10], decimalNumber[10], decimalSeparator[1]

* Assign tag a two-character string representing the source field tag, like: tag = 'ab', * which already contains the number as a string, still to be rounded off to two decimals.

tag = 'op' decimalSeparator = '.' maxOcc = repcnt(!tag) occ = 1 while (occ <= maxOcc) { if (!tag[occ] <> '') { !tag[occ] = round$(val(!tag[occ]), 2) integerNumber = '' decimalNumber = '' decimalNumber = after$(1, !tag[occ], decimalSeparator) if (len(decimalNumber) < 2) { /* Padding is required integerNumber = before$(1, !tag[occ], decimalSeparator) if (decimalNumber = '') { decimalNumber = '00' } else { decimalNumber = decimalNumber + '0' } !tag[occ] = integerNumber + decimalSeparator + decimalNumber } } occ = occ + 1 }

Example

result = round(1200.125, 2)

Result

result is '1200.13'