Skip to main content
numberToWords converts numeric values into Persian word form (123"صد و بیست و سه").

Function

Input rules

  • Accepts number | string. Strings are first run through removeCommas.
  • The numeric value must be a safe integer (Number.isSafeInteger).
  • Non-safe-integer input (floats, values above Number.MAX_SAFE_INTEGER) returns a PersianToolsTypeError instance (the function returns the error; it does not throw).
  • Negative integers work — output is prefixed with منفی.

Return type — union with the error

The return type is string | PersianToolsTypeError. Don’t assume it’s a plain string.

Range

  • Min: -Number.MAX_SAFE_INTEGER
  • Max: Number.MAX_SAFE_INTEGER (≈ 9.007e15)
  • Floats: rejected.

Ordinal mode

{ ordinal: true } runs the result through addOrdinalSuffix. Suffix rules:
  • Ends with ی → append اُم (with leading space).
  • Ends with سه → strip last 2 chars, append سوم.
  • Otherwise → append م.

Pitfalls

  • No currency or scale options. Older docs reference them — they do not exist.
  • No locale switching. Output is always Persian words separated by و.
  • Return is string | PersianToolsTypeError — guard accordingly.
  • Persian-digit string input is not auto-normalizedremoveCommas only handles commas. Run autoConvertDigitsToEN upstream if needed.

Composition

Source

src/modules/numberToWords/index.ts, constants.ts, types.ts · Tests: test/NumberToWords.spec.ts