Pad number

JavaScript, String, Math · Oct 3, 2020

Pads a given number to the specified length.

const padNumber = (n, l) => `${n}`.padStart(l, '0');
padNumber(1234, 6); // '001234'

More like this

  • Pad string

    Pads a string on both sides with the specified character, if it's shorter than the specified length.

    JavaScript, String · Oct 22, 2020

  • Pretty-print number of bytes

    Converts a number in bytes to a human-readable string.

    JavaScript, String · Oct 22, 2020

  • Random alphanumeric string

    Generates a random string with the specified length.

    JavaScript, String · Oct 22, 2020