Skip to main content

Overview

This function formats a number according to a given style.

Parameters

formatNumber(number, style)
  • Variable: The number to format.
  • Style: The desired format.
    • none: No formatting, just the plain number.
    • currency: Formats as local currency (e.g., $1,234.56 or R$ 1.234,56).
    • decimal: Standard decimal formatting with grouping separators (e.g., 1,234.56).
    • percent: Formats as a percentage (e.g., 50%).
    • scientific: Scientific notation (e.g., 1.23E3).
    • spellOut: Spells the number in words (e.g., one thousand two hundred thirty-four).
    • ordinal: Formats as an ordinal number (e.g., 1st, 2nd, 3rd).
    • currencyISOCode: Currency with ISO code (e.g., USD 1,234.56).
    • currencyPlural: Currency formatted using plural rules (e.g., 1 dollar, 2 dollars).
    • currencyAccounting: Currency formatted for accounting (e.g., negative numbers in parentheses: ($1,234.56)).

Example

formatNumber(1234.56, "decimal")
Returns "1,234.56" (formatted with commas and proper decimal places).
formatNumber(0.75, "percent")
Returns "75%".