# adddecimal,subdecimal,muldecimal,divdecimal

### adddecimal(value1, value2)

Returns the sum of the two Number arguments value1 and value2, returns the results as a Decimal.

### subdecimal(value1, value2)

Returns the result of the second Number argument (value2) subtracted from the first Number argument (value1), as a Decimal.

### muldecimal(value1, value2)

Returns the product of the two Number arguments value1 and value2, as a Decimal.

### divdecimal(value1, value2, roundingMode), divdecimal(value1, value2, scale, roundingMode)

Returns a Decimal whose value is (value1 / value2). If a scale argument is supplied the returned Decimal will have the scale specified, if a scale is not specified, the returned Decimal will have the same scale as value1. If rounding must be performed to generate a result with the given scale, the specified rounding mode is applied. Generates an exception if value2 == 0 or scale < 0. Also generates an exception if roundingMode does not represent a valid rounding mode.

## Arguments

Argument | Data Type | Description
value1, value2 | Number | Number arguments specified by the user.
scale | integer | Represents the number of decimal digits to the right of the decimal point.
roundingMode | integer or String | Corresponds to one of four rounding modes provided to give the user control over rounding behavior, forcing the user to explicitly specify a rounding behavior for operations capable of discarding precision (i.e. divdecimal and decimalsetscale). The appropriate int or String to specify the required mode should be selected according to the table of rounding modes.

### Rounding modes:

int | String | Corresponding roundingMode
1 | "rup" | Decimal.ROUND_UP Always increment the digit prior to a non-zero discarded fraction. Note that this rounding mode never decreases the magnitude. (Rounds away from zero.)
2 | "rdown" | Decimal.ROUND_DOWN Never increment the digit prior to a discarded fraction (i.e., truncate). Note that this rounding mode never increases the magnitude. (Rounds towards zero.)
3 | "rhalfup" | Decimal.ROUND_HALF_UP Behave as for ROUND_UP if the discarded fraction is >= .5; otherwise, behave as for ROUND_DOWN. (Rounds towards "nearest neighbor" unless both neighbors are equidistant, in which case rounds up.)
4 | "rhalfdown" | Decimal.ROUND_HALF_DOWN Behave as for ROUND_UP if the discarded fraction is > .5; otherwise, behave as for ROUND_DOWN. (Rounds towards "nearest neighbor" unless both neighbors are equidistant, in which case rounds down.)

## Returns

A Decimal value, the result of the function carried out on the two Number arguments supplied.

## Description

A series of functions designed to carry out simple arithmetic operations on Number arguments, returning a Decimal result. Note: care should be taken when using Decimals that the scale (i.e. the number of decimal places) has been set correctly, otherwise calculations using Decimals with large numbers of decimal places may give unexpected or inaccurate results. See decimalsetscale() for more information on setting scale.

## Examples

> Assume the following variables:

> > bd = Decimal(123456789.00), value1 = 1.01
> > mulValue1 = Decimal(12143245.10), mulValue2 = Decimal(12143244.10)
> > divValue1 = 7234567890.12, divValue2 = Decimal(123456789.9)

Example | Returns | Description
adddecimal(bd, value1) | Decimal(123456790.01) | Decimal returned has same scale as bd.
subdecimal(bd, value1) | Decimal(123456787.99) | Decimal returned has same scale as bd
muldecimal(mulValue1,mulValue2) | Decimal(147458389415428.90) | Decimal returned has same scale as mulValue1
divdecimal(divValue1, divValue2,"rup") | Decimal(58.61) | No scale specified - Decimal returned has same scale as divValue1, rounding mode corresponds to ROUND_UP
divdecimal(divValue1, divValue2, 1, "rdown") | Decimal(58.6) | Decimal returned has scale of 1, rounding mode corresponds to ROUND_DOWN
divdecimal(divValue1, divValue2, 1, 1) | Decimal(58.61) | Decimal returned has scale of 1, rounding mode argument of 1 corresponds to ROUND_UP
divdecimal(divValue1, divValue2, 1, 2) | Decimal(58.6) | Decimal returned has scale of 1, rounding mode argument of 2 corresponds to ROUND_DOWN

## See Also

decimalsetscale(), Decimal Variables