# truncate

operator

 Library: Floating point number support (OMFLOAT) Import : omfloat.xmd Library: Binary coded decimal numbers (OMBCD) Import : ombcd.xmd Returns: a BCD or floating point number truncated to a whole number

Declaration
```export overloaded bcd function
truncate    value bcd b
by value bcd base optional

truncate    value float b
by value float base optional
```

Purpose

Use truncate to cut off trailing digits from:

• a BCD number
• a floating point number
• an integer coerced into a BCD or floating point number

If you do not specify the precision, you will truncate to the nearest integer. If a precision is specified, the value is truncated to the multiple of that precision.

Import either ombcd.xmd or omfloat.xmd 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:

```  import "ombcd.xmd" unprefixed
process
local bcd pi initial {"3.14179"}
local bcd area

output "Area of a circle (truncated) with radius of "
|| " = "
|| "d" % area
|| "%n"
; Output: "Area of a circle (truncated) with radius of 75 = 17672"
```

### Floating Point Example:

Calculate the area of a circle:

```  import "omfloat.xmd" unprefixed
process
local float area

output "Area of a circle (truncated) with radius of "
|| " = "
|| "d" % area
|| "%n"
; Output: "Area of a circle (truncated) with radius of 75 = 17672"
```

You can specify the precision of the rounding. The following program uses a precision of 0.01 to truncate the value at the whole cents position:

```  import "ombcd.xmd" unprefixed
process
local bcd exchange-rate initial {1.4994}
local bcd us-price initial {125.00}

set canadian-price to truncate (us-price*exchange-rate) by 0.01
output "US "
|| "<\$,NNZ.ZZ>" % us-price
|| " = "