Package: effect
Module: BigDecimal
Computes the decimal remainder safely when one operand is divided by a second operand.
When to use
Use to compute a decimal remainder while representing division by zero as
Option.none.
Details
If the divisor is 0, the result will be Option.none().
Example (Computing remainders safely)
import { BigDecimal, Option } from "effect"
import * as assert from "node:assert"
assert.deepStrictEqual(
BigDecimal.remainder(
BigDecimal.fromStringUnsafe("2"),
BigDecimal.fromStringUnsafe("2")
),
Option.some(BigDecimal.fromStringUnsafe("0"))
)
assert.deepStrictEqual(
BigDecimal.remainder(
BigDecimal.fromStringUnsafe("3"),
BigDecimal.fromStringUnsafe("2")
),
Option.some(BigDecimal.fromStringUnsafe("1"))
)
assert.deepStrictEqual(
BigDecimal.remainder(
BigDecimal.fromStringUnsafe("-4"),
BigDecimal.fromStringUnsafe("2")
),
Option.some(BigDecimal.fromStringUnsafe("0"))
)
See
remainderUnsafe for remainder calculation that throws when the divisor is zerodivide for decimal quotient calculationSignature
declare const remainder: { (divisor: BigDecimal): (self: BigDecimal) => Option.Option<BigDecimal>; (self: BigDecimal, divisor: BigDecimal): Option.Option<BigDecimal>; }
Since v2.0.0