effect-io-ai

Package: effect
Module: BigDecimal

BigDecimal.round

Computes a rounded BigDecimal at the given scale with the specified rounding mode.

When to use

Use to round a decimal at a requested scale with an explicit rounding mode.

Example (Rounding decimals)

import { BigDecimal } from "effect"
import * as assert from "node:assert"

assert.deepStrictEqual(
  BigDecimal.round(BigDecimal.fromStringUnsafe("145"), { mode: "from-zero", scale: -1 }),
  BigDecimal.fromStringUnsafe("150")
)
assert.deepStrictEqual(
  BigDecimal.round(BigDecimal.fromStringUnsafe("-14.5")),
  BigDecimal.fromStringUnsafe("-15")
)

See

Signature

declare const round: { (options: { scale?: number; mode?: RoundingMode; }): (self: BigDecimal) => BigDecimal; (n: BigDecimal, options?: { scale?: number; mode?: RoundingMode; }): BigDecimal; }

Source

Since v3.16.0