effect-io-ai

Package: effect
Module: BigDecimal

BigDecimal.truncate

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

Signature

declare const truncate: { (scale: number): (self: BigDecimal) => BigDecimal; (self: BigDecimal, scale?: number): BigDecimal; }

Source

Since v3.16.0