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
0to represent digits that must appear (pads with zeros if needed). - Use
#for optional digits. - Use
,to include thousands separators. - Use
.to define decimal precision.
- Use
Behavior
- If
valueis a string, it’s returned unchanged. - If
valueis a Date, it’s internally converted to a timestamp before formatting. - If
valueis not a finite number, string, or date, an error is thrown. - Rounding is handled similar to Excel’s
TEXTfunction — 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
TEXTfunction 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.