Browse documentation

NumberFormatter

Builds and transforms a numeric value before locale-aware formatting.

Table of contents

Category

Value

Import

js
import { NumberFormatter } from "valyrian.js/money";

Public signature

ts
NumberFormatter.create(value?: number | string, shiftDecimal?: boolean): NumberFormatter

API form

NumberFormatter is a class with a private constructor. Obtain an instance through NumberFormatter.create(...).

Properties and methods

ts
NumberFormatter.create(value = 0, shiftDecimal = false): NumberFormatter
readonly value: number
set(newValue: number | string, shiftDecimal = false): this
format(digits = 2, options = { style: "currency", currency: "USD" }, locale = "en"): string
fromDecimalPlaces(decimalPlaces: number): this
toDecimalPlaces(decimalPlaces: number): this
getDecimalPlaces(): number
shiftDecimalPlaces(): this

Input behavior

create() and set() remove nonnumeric characters. An input that cannot produce a number becomes 0. shiftDecimal removes decimal separators before conversion.