Skip to main content

number

Number module - Number formatting, validation, calculations, and conversions.

Provides practical utilities for working with numbers in real-world applications, including currency formatting, percentage calculations, byte sizes, and more.

Example

import * as N from 'receta/number'

// Currency formatting
N.toCurrency(1234.56, { currency: 'USD' }) // => "$1,234.56"

// Percentage calculations
pipe(
N.percentage(25, 100),
N.toPercent(1)
) // => "25.0%"

// Byte size formatting
N.toBytes(1048576) // => "1.00 MB"

// Safe parsing
N.fromString("123.45") // => Ok(123.45)

References

average

Re-exports average


ByteOptions

Re-exports ByteOptions


ByteUnit

Re-exports ByteUnit


clamp

Re-exports clamp


CompactOptions

Re-exports CompactOptions


CurrencyOptions

Re-exports CurrencyOptions


format

Re-exports format


FormatOptions

Re-exports FormatOptions


fromBytes

Re-exports fromBytes


fromCurrency

Re-exports fromCurrency


fromString

Re-exports fromString


inRange

Re-exports inRange


interpolate

Re-exports interpolate


InvalidOperationError

Re-exports InvalidOperationError


isFinite

Re-exports isFinite


isInteger

Re-exports isInteger


isNegative

Re-exports isNegative


isPositive

Re-exports isPositive


normalize

Re-exports normalize


ParseError

Re-exports ParseError


parseFormattedNumber

Re-exports parseFormattedNumber


percentage

Re-exports percentage


random

Re-exports random


ratio

Re-exports ratio


round

Re-exports round


roundTo

Re-exports roundTo


step

Re-exports step


sum

Re-exports sum


toBytes

Re-exports toBytes


toCompact

Re-exports toCompact


toCurrency

Re-exports toCurrency


toOrdinal

Re-exports toOrdinal


toPercent

Re-exports toPercent


toPrecision

Re-exports toPrecision