Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

$formatNumber always pads numbers with '0' #161

Closed
deepilla opened this issue Feb 21, 2018 · 1 comment
Closed

$formatNumber always pads numbers with '0' #161

deepilla opened this issue Feb 21, 2018 · 1 comment
Labels

Comments

@deepilla
Copy link
Contributor

The formatNumber function sometimes needs to pad numbers with zeroes. For example, this expression:

$formatNumber(2, "000.000")

returns the number 2 padded to 3 digits before and after the decimal place:

"002.000"

If I provide a custom zero digit, I'd expect formatNumber to use it for the padding. But this expression:

$formatNumber(2, "AAA.AAA", {"zero-digit": "A"})

produces this:

"00C.000"

As you might expect, the '2' is now a 'C' but it's padded with '0' instead of the zero digit specified (I used the letter 'A' but the outcome is the same whatever character you choose*).

The same applies to exponents that need padding, e.g.

$formatNumber(0.1, "AeAAA", {"zero-digit": "A"})

returns:

"Be-00B"

[*] When I was trying out these examples, I noticed that formatNumber doesn't handle non-BMP zero digit characters such as '𝟶' (U+1D7F6). I suspect this is related to issue 156 but I haven't investigated further.

@andrew-coleman
Copy link
Member

Good spot. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants