question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ability to "pad" a number in formatting

See original GitHub issue

See also: https://github.com/adamwdraper/Numeral-js/issues/123

Which references this implementation: https://gist.github.com/resident-uhlig/7906919

I don’t love the syntax #N# but at least it works!

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
atuttlecommented, Jul 29, 2015

FWIW, I’ve worked with other languages/libraries that use the number of digits in the format string as if they were significant-digits; so:

5.format('000')
=> 005

15.format('000,000.00')
=> 000,015.00

IMO that would be the best possible implementation (seems very clean to me) but I’m not sure how feasible it is to work that into the current formatting implementation, or if it would break any existing expectations at all.

0reactions
BenjaminVanRyseghemcommented, Oct 5, 2015

That’s indeed the case.

I will add documentation with the next release.

But if you want to propose a PR before, feel free 😄

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to: Pad a Number with Leading Zeros | Microsoft Learn
You can add leading zeros to an integer by using the "D" standard numeric format string with a precision specifier. You can add...
Read more >
How to Add Leading Zeros to Numbers or Text with Uneven ...
Solution #2: Padding Numbers or Text with the RIGHT function · Step 1: Add the Leading Zeros. The first step is to add...
Read more >
Excel formula: Pad a number with zeros - Excelchat - Got It AI
While working with Excel, we are able to pad a number with zeros by using the TEXT and REPT functions, or by simply...
Read more >
Pad a number with leading zeros in JavaScript - Stack Overflow
In JavaScript, I need to have padding. For example, if I have the number 9, it will be "0009". If I have a...
Read more >
Quick Tips: Adding Leading Zero to Integer Values (Padding ...
Padding Numbers Greater than 0 with Zero in Power Query. Each format string can have up to 4 sections. We can separate each...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found