Package: effect
Module: BigDecimal
Computes a truncated BigDecimal at the given scale. This removes fractional digits beyond the scale,
rounding toward zero.
When to use
Use when you need to discard fractional digits beyond a scale rather than round half up, half down, or toward an infinity.
Example (Truncating decimals)
import { BigDecimal } from "effect"
console.log(BigDecimal.truncate(BigDecimal.fromStringUnsafe("145"), -1)) // BigDecimal(140)
console.log(BigDecimal.truncate(BigDecimal.fromStringUnsafe("-14.5"))) // BigDecimal(-14)
See
round for configurable rounding modesceil for rounding toward positive infinityfloor for rounding toward negative infinitySignature
declare const truncate: { (scale: number): (self: BigDecimal) => BigDecimal; (self: BigDecimal, scale?: number): BigDecimal; }
Since v3.16.0