

Related Syntax  Related Concepts  
operator  round 
Return type: BCD
Returns:
A BCD or floating point number rounded to the nearest value. If a precision is specified, the value is rounded to the nearest multiple of the precision specifier. If bankersnearest is specified, the value is rounded to the nearest even multiple of the precision specifier.
round bcdexpression ((nearest  bankersnearest) precision)? round floatexpression ((nearest  bankersnearest) precision)?
Use this function to round any of the following to the nearest digit or decimal place specified:
If you do not specify the precision, you will round to the nearest integer.
Include either ombcd.xin or omfloat.xin in your program after deciding whether you want BCD mathematics (excellent for financial calculations) or floating point mathematics (excellent for extremely large numbers).
BCD Example:
Calculate the area of a circle:
include "ombcd.xin" process local bcd pi initial {"3.14179"} local bcd radius initial {"74"} local bcd area set area to round (pi * radius * radius) output "area of circle with radius "  "d" % radius  " = "  "d" % area  "%n"
Floating Point Example:
Calculate the area of a circle:
include "omfloat.xin" process local float pi initial {"3.14179"} local float radius initial {"74"} local float area set area to round (pi * radius * radius) output "Area of circle with radius "  "d" % radius  " = "  "d" % area  "%n"
You can specify the precision of the rounding. The following program uses a precision of 0.01 to round to the nearest cent:
include "ombcd.xin" process local bcd exchangerate initial {1.4356} local bcd usprice initial {129.95} local bcd canadianprice set canadianprice to round (usprice * exchangerate) nearest bcd 0.01 output "us "  "<$,NNZ.ZZ>" % usprice  " = "  "<$,NNZ.ZZ>" % canadianprice  " cdn %n"
You can use bankers rounding (available only with the BCD library) to resolve ties to the nearest even multiple of the precision specifier:
; Bankersnearest rounds to the nearest even digit include "ombcd.xin" process local bcd x initial {9.95} local bcd y initial {9.85} local bcd roundedx local bcd roundedy set roundedx to round (x) bankersnearest 0.1 set roundedy to round (y) bankersnearest 0.1 output "Roundedx = "  "d" % roundedx  "%n"  "Roundedy = "  "d" % roundedy  "%n" ; Output: "Roundedx = 10 ; Roundedy = 9.8"
The precision specifier must be a power of 10, or an error occurs.
Related Syntax ceiling floor truncate 
Related Concepts BCD data type 
 