Browse the docs

formatBase

Writes a whole number as text in a base from 2 to 36, with optional zero padding.

Details #

formatBase(number, base, digits?) takes two or three arguments and returns text.

  • number is cut to a whole number (decimals are dropped, not rounded).

  • base is 2 to 36. Letters above 9 come back in capitals, so base 16 gives FF.

  • digits pads with zeros on the left to at least that many characters. Without it there is no padding.

A negative number keeps its minus sign in front of the padding: formatBase(-5, 2, 4) is -0101. The result is text; use hex, oct or bin to turn it back into a number.

Parameters #

Takes 2 to 3 arguments. {{ formatBase(text, b, c?) }}

Examples #

formatBase(255, 16)
→ FF
formatBase(5, 2, 8)
→ 00000101
formatBase(n, 16, 6)
→ 001000
Sample variableValue
n4096

Gotchas #

  • A base below 2 or above 36 stops the step: formatBase() works in bases 2 to 36.

  • Anything that isn't a number is an error: formatBase() needs a number, got text.

  • Keyboard Maestro has no function by this name, so nothing imports to it.