Browse the docs

number

Turns text, true/false or nothing into a number, or stops with an error.

Keyboard Maestro: Calculate

Details #

number(value) takes exactly one argument and returns a number.

  • A number stays a number.

  • Text that is wholly a decimal number (optional sign, point or e exponent, surrounding spaces allowed) becomes that number: number("42") is 42, number(" 1.5 ") is 1.5.

  • true is 1, false is 0, and nothing (null) is 0.

  • Anything else is an error: can't turn "abc" into a number.

Parameters #

Takes 1 argument. {{ number(text) }}

Examples #

number("42") + 1
→ 43
number(input) * 2
→ 42
Sample variableValue
input21
number(flag)
→ 1
Sample variableValue
flagtrue

Gotchas #

  • "5" + 1 is the text 51, not 6. Use number("5") + 1. Subtraction, multiplication, division and % convert numeric text on their own.