Skip to main content

TEXT

Formats a number, date, or string into text according to a specified format pattern.
This function behaves similarly to Excel’s TEXT() function and supports numeric, date, and string inputs.

Syntax

TEXT(value, format)

Arguments

  • value: The value to format. Can be a number, string or Date resolving to one of these.
  • format: A format string that defines how the value should be displayed.
    • Use 0 to represent digits that must appear (pads with zeros if needed).
    • Use # for optional digits.
    • Use , to include thousands separators.
    • Use . to define decimal precision.

Behavior

  • If value is a string, it’s returned unchanged.
  • If value is a Date, it’s internally converted to a timestamp before formatting.
  • If value is not a finite number, string, or date, an error is thrown.
  • Rounding is handled similar to Excel’s TEXT function — halves are rounded away from zero.

Example

TEXT(1234.56, "0.00") → Returns "1234.56" TEXT(9, "0000") → Returns "0009" TEXT(1234.56, "#,##0.00") → Returns "1,234.56" TEXT(-5.2, "0.00") → Returns "-5.20"

Notes

  • The TEXT function can be used to generate formatted output for display, exporting, or generating string-based IDs.
  • For date values, consider using a dedicated date formatting function if you need human-readable date strings.