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
eexponent, surrounding spaces allowed) becomes that number:number("42")is 42,number(" 1.5 ")is 1.5.trueis 1,falseis 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→
43number(input) * 2→
42| Sample variable | Value |
|---|---|
input | 21 |
number(flag)→
1| Sample variable | Value |
|---|---|
flag | true |
Gotchas #
"5" + 1is the text51, not 6. Usenumber("5") + 1. Subtraction, multiplication, division and%convert numeric text on their own.