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 n1number The first number.
n2number The second number.
decimalsnumber <optional>
The number of decimal digits to keep.
fixedboolean <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 n1number The dividend.
n2number The divisor.
decimalsnumber <optional>
The number of decimal digits to keep.
fixedboolean <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 newValuenumber The number to subtract from.
oldValuenumber The number to subtract.
absoluteboolean <optional>
false trueto return the absolute value of the difference.Returns:
The difference between
newValueandoldValue, or the absolute value of it ifabsoluteistrue.- 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 newValuestring | number The new value.
oldValuestring | number The old value.
precisionnumber <optional>
What precision should we use. If not specified, falls back to the value in the user preferences.
Returns:
trueif 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 n1number The first number.
n2number The second number.
decimalsnumber <optional>
The number of decimal digits to keep.
fixedboolean <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 numbernumber The number to round.
decimalsnumber <optional>
The number of decimal digits to keep.
fixedboolean <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 n1number The number to subtract from.
n2number The number to subtract.
decimalsnumber <optional>
The number of decimal digits to keep.
fixedboolean <optional>
Returns value as fixed string using the specified number of decimals.
Returns:
The difference between the two numbers.
- Type
- string