Browse the docs

numberFormat

Formats a number with a pattern such as #,##0.00.

Keyboard Maestro: CalculateFormat

Details #

numberFormat(number, pattern) takes exactly two arguments and returns text.

number is a number, or text that reads as one. pattern is a number format pattern: 0 is a digit that always shows, # one that shows only when needed, . starts the decimals and , turns on grouping of thousands. Examples: 0.00 gives two decimals, #,##0 groups thousands, 000 pads to three digits. Negative numbers get a minus sign in front of the whole pattern.

Output always uses . for the decimal point and , for grouping, whatever the Mac's region.

Parameters #

Takes 2 arguments. {{ numberFormat(text, b) }}

Examples #

numberFormat(1234567.891, "#,##0.00")
→ 1,234,567.89
numberFormat(7, "000")
→ 007
numberFormat(0.5, "0.0")
→ 0.5

Gotchas #

  • Not a number is an error: numberFormat() needs a number, got text.

  • Grouping only switches on when the pattern contains a comma.