Languages
[Edit]
EN

TypeScript - pad left number in string with zeros or spaces to get determined length

3 points
Created by:
Mariam-Barron
811

In TypeScript, it is possible to pad left a number with any character in the following ways.

1. Custom solution example

Edit

2. Polifill example

Edit

ECMAScript 2017 introduced a function that pads numbers.

Simple steps:

1. install ts-polyfill package:

2. inside tsconfig.json add es2017.string to the lib.

3. Run the example

The example below was executed under Node.js:

Warning: under Node.js do not forget to add console.log() declarations.

Output:

See also

Edit
  1. TypeScript - pad right number in string with zeros or spaces to get determined length 
1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join