/ (divide)

operator

Return type: Integer
Returns:       The result of dividing the first argument by the second argument.

Syntax
numeric-expression / numeric-expression

Purpose

You can divide two numeric values using the / operator.

To divide BCD numbers, you must import the ombcd.xmd file in your program. To divide floating point numbers, import the omfloat.xmd file.

You can divide values of mixed data types (for example, BCD numbers and integers) as long as you follow the rules listed in Operations with mixed data types.

Always surround arithmetic operators with spaces.

BCD Example:

; Sales-per-square-foot = Sales / Floor space
import "ombcd.xmd" unprefixed
process
local bcd sales-per-square-foot
local bcd sales initial {339000}
local bcd floor-space initial {20015}

set sales-per-square-foot to sales / floor-space
output "Sales per square foot: "
|| "<\$,NNZ.ZZ>" % sales-per-square-foot
|| "%n"
; Output: 'Sales per square foot: \$16.94'

Floating Point Example:

; travel-time = distance-to-proxima-centauri / light-speed
import "omfloat.xmd" unprefixed
process
local float distance-to-proxima-centauri initial {40493000000000}
local float light-speed-per-day initial {25902068371.2}
; light-speed is 299,792.458 km/second, or 25,902,068,371.2 km/day
local float travel-time

set travel-time to distance-to-proxima-centauri / light-speed-per-day
output "Travel time is " || "d" % (travel-time / 365.25) || " years.%n"
; Output: 'Travel time is 4.280113477215875 years.'

Mixed Data Type Example:

; Parkland per capita = (Acres of park) / (city population)
import "ombcd.xmd" unprefixed
process
local bcd edmonton-park-acreage initial {18286.14}
local integer edmonton-population initial {648284}
local bcd parkland-per-capita

set parkland-per-capita to edmonton-park-acreage / edmonton-population
output "Parkland per capita in Edmonton: "
|| "d" % parkland-per-capita
|| "%n"
; Output: 'Acres of parkland per capita in Edmonton:  0.0282069895292803

If the result of a division does not fit in the data type of the arguments, the value returned is truncated to fit the data type. For instance, the result of dividing the integer 10 by 4 (2.5) is truncated to 2 to fit the integer data type. The result of dividing the BCD number 2.5 by the BCD number 0.000143 (17482.517482517482517482517482517) is truncated to 17482.5174825174825174 to fit the BCD data type.

The word "divide" is a deprecated synonym for /.

For floating point numbers, overflow and underflow values return infinity and zero, respectively.

BCD numbers and integers cannot overflow, but both data types return an underflow of 0.

Related Concepts