Module: Utils/Math

Math module provides utility methods for working with basic calculations that JS normally fails to do well.

Methods


<static> add(n1, n2 [, decimals] [, fixed])

Adds two numbers as integer values.

Parameters:
Name Type Argument Description
n1 number

The first number.

n2 number

The second number.

decimals number <optional>

The number of decimal digits to keep.

fixed boolean <optional>

Returns value as fixed string using the specified number of decimals.

Returns:

The sum of the two numbers.

Type
string

<static> div(n1, n2 [, decimals] [, fixed])

Divides two numbers as integer values.

Parameters:
Name Type Argument Description
n1 number

The dividend.

n2 number

The divisor.

decimals number <optional>

The number of decimal digits to keep.

fixed boolean <optional>

Returns value as fixed string using the specified number of decimals.

Returns:

The quotient.

Type
string

<static> getDifference(newValue, oldValue [, absolute])

Gets the difference between two numbers.

Parameters:
Name Type Argument Default Description
newValue number

The number to subtract from.

oldValue number

The number to subtract.

absolute boolean <optional>
false

true to return the absolute value of the difference.

Returns:

The difference between newValue and oldValue, or the absolute value of it if absolute is true.

Type
string | number

<static> isDifferentWithPrecision(newValue, oldValue [, precision])

Checks to see if two values are different according to the given precision.

Parameters:
Name Type Argument Description
newValue string | number

The new value.

oldValue string | number

The old value.

precision number <optional>

What precision should we use. If not specified, falls back to the value in the user preferences.

Returns:

true if the values are different according to the given precision.

Type
boolean

<static> mul(n1, n2 [, decimals] [, fixed])

Multiplies two numbers as integer values.

Parameters:
Name Type Argument Description
n1 number

The first number.

n2 number

The second number.

decimals number <optional>

The number of decimal digits to keep.

fixed boolean <optional>

Returns value as fixed string using the specified number of decimals.

Returns:

The product of the two numbers.

Type
string

<static> round(number [, decimals] [, fixed])

Rounds a number to specified decimals as integer value.

Parameters:
Name Type Argument Description
number number

The number to round.

decimals number <optional>

The number of decimal digits to keep.

fixed boolean <optional>

Returns value as fixed string.

Returns:

The rounded number.

Type
string

<static> sub(n1, n2 [, decimals] [, fixed])

Subtracts two numbers as integer values.

Parameters:
Name Type Argument Description
n1 number

The number to subtract from.

n2 number

The number to subtract.

decimals number <optional>

The number of decimal digits to keep.

fixed boolean <optional>

Returns value as fixed string using the specified number of decimals.

Returns:

The difference between the two numbers.

Type
string