SADD(), SDIV(), SMUL(), SSUB() |
|
|
The SADD(), SDIV(), SMUL() and SSUB() functions perform arithmetic on numeric strings of any length.
Format
SADD(a, b) SDIV(a, b {, r{, dp}}) SMUL(a, b) SSUB(a, b)
where
These four functions perform addition, division, multiplication and subtraction respectively. The values passed in as arguments a and b must be strings that contain only digits with an optional leading minus sign and/or decimal point. The behaviour of these functions with a malformed numeric string is undefined.
The returned value will be a numeric string. Trailing zeroes after the decimal point are removed.
The SDIV() function has two optional arguments. The third argument, r, is used to return the remainder as a numeric string. The fourth argument, dp, specifies the precision as the maximum number of decimal places to appear in the result, defaulting to zero if omitted. If dp is to be specified but the remainder value is not required, the third argument can specified as a meaningless constant value such as zero or a null string. The SDIV() function truncates excess decimal places without rounding.
Examples
DISPLAY SADD('12345678901234567890', '99999888887777766666') DISPLAY SSUB('12345678901234567890', '987654321') DISPLAY SMUL('12345678901234567890', '99999888887777766666') DISPLAY SMUL('123.456', '17.81')
The above four display statements produce: 112345567789012334556 12345678900246913569 1234566518367639093641977791581755954740 2198.75136
DISPLAY SDIV('12345678901234567890', '987654321', R) : ', Remainder ' : R DISPLAY SDIV('335', '113', R, 6)
The above two statements produce 12499999887, Remainder 339506163 3.141592
|