Mathematical operations in ScriptCode
Mathematical operations in ScriptCode
It is recommended that all mathematical operations in scriptCode be performed through the object BigDecimal.
API
big-decimal.interface.ts
big-decimal.interface.tsBigDecimal
interface BigDecimal {
valueOf(value: string | number | BigDecimal): BigDecimal
add(augend: string | number | BigDecimal): BigDecimal
subtract(subtrahend: string | number | BigDecimal): BigDecimal
multiply(multiplicand: string | number | BigDecimal): BigDecimal
divide(divisor: string | number | BigDecimal): BigDecimal
divide(divisor: string | number | BigDecimal, roundingMode: string): BigDecimal
divide(divisor: string | number | BigDecimal, scale: number): BigDecimal
divide(divisor: string | number | BigDecimal, scale: number, roundingMode: string): BigDecimal
setScale(newScale: number): BigDecimal
setScale(newScale: number, roudingMode: string): BigDecimal
equals(equated: string | number | BigDecimal): boolean
compareTo(compared: string | number | BigDecimal): int
}decimal-format.interface.ts
decimal-format.interface.tsrounding-mode.interface.ts
rounding-mode.interface.tsdecimal-format-symbols.interface.ts
decimal-format-symbols.interface.tsrandom.interface.ts
random.interface.tsBigDecimal
Creating an object
Object BigDecimal is immutable.
Operations such as add() do not change the value, they require assigning the result to a variable.
Mathematical operations
Addition
Subtraction
Division
Multiplication
Setting the scale
Comparison and equality
DecimalFormat
Class for formatting decimal numbers in different languages. Documentation: DecimalFormat (Java)
Example
Patterns
0
Placeholder for a digit
#
Placeholder for a digit (0 omitted)
,
Decimal separator
%
Multiplies by 100 and displays as a percent
E
Scientific notation
Rounding numbers (RoundingMode)
RoundingMode)HALF_UP
Rounds up if the fractional part ≥ 0.5
CEILING
Always up to the nearest integer
DOWN
Always down
FLOOR
Down to the nearest integer
HALF_DOWN
Down if < 0.5
HALF_EVEN
Bankers' rounding (to the even number)
Preferred result scales
https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/math/BigDecimal.html
Add
max(addend.scale(), augend.scale())
Subtract
max(minuend.scale(), subtrahend.scale())
Multiply
multiplier.scale() + multiplicand.scale()
Divide
dividend.scale() - divisor.scale()
Square root
radicand.scale()/2
Random
Generating UUID identifiers (version 4):
Last updated
Was this helpful?
