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

Fixed precision for average #190

Closed
tehandyb opened this Issue Jul 19, 2016 · 3 comments

Comments

Projects
None yet
2 participants
@tehandyb

tehandyb commented Jul 19, 2016

I saw the average formatter lets you specify precision when the number gets rounded up, but I have commonly had the use case where I want a fixed precision of 3 digits no matter what the number was and whether it was rounded or not.

So numbro(12345).format('3a') would give 12.3k instead of currently 12k

@chrisnicola

This comment has been minimized.

Show comment
Hide comment
@chrisnicola

chrisnicola Oct 7, 2016

Contributor

This seems to be a bug, for every value less than 4 it does exactly the same thing. You can even see this behaviour happening in the docs right now.

Contributor

chrisnicola commented Oct 7, 2016

This seems to be a bug, for every value less than 4 it does exactly the same thing. You can even see this behaviour happening in the docs right now.

@chrisnicola

This comment has been minimized.

Show comment
Hide comment
@chrisnicola

chrisnicola Oct 7, 2016

Contributor

Seems the way to do this is '000a' rather than '3a'. I must say I find the inconsistency here confusing though.

Contributor

chrisnicola commented Oct 7, 2016

Seems the way to do this is '000a' rather than '3a'. I must say I find the inconsistency here confusing though.

chrisnicola added a commit to chrisnicola/numbro that referenced this issue Oct 7, 2016

Fix BenjaminVanRyseghem#190 Allow abbreviation precision for < 4
Currently for some reason when using abbreviations like `'0,0a`  you can't specify the number of visible digits of precision for any value less than 4. So while `'4,0a'` will change `1234567` to `1,234k` the result of `'3,0a'` is `1m` instead of `1.23m` as expected.

This is simply caused by a conditional that skips setting the precision in the formatting.
@chrisnicola

This comment has been minimized.

Show comment
Hide comment
@chrisnicola

chrisnicola Oct 7, 2016

Contributor

So I was wrong, doing 000 will add leading zeros. I've submitted a patch for this. For reasons I don't understand it simply skips precision formatting for values less than 4.

Contributor

chrisnicola commented Oct 7, 2016

So I was wrong, doing 000 will add leading zeros. I've submitted a patch for this. For reasons I don't understand it simply skips precision formatting for values less than 4.

chrisnicola added a commit to chrisnicola/numbro that referenced this issue Oct 20, 2016

Fix BenjaminVanRyseghem#190 Allow abbreviation precision for < 4
Currently for some reason when using abbreviations like `'0,0a`  you can't specify the number of visible digits of precision for any value less than 4. So while `'4,0a'` will change `1234567` to `1,234k` the result of `'3,0a'` is `1m` instead of `1.23m` as expected.

This is primarily caused by a conditional that skips setting the precision in the formatting.

This commit changes how the algorithm determines if decimal places will be required and how many are required. We first compute the abbreviated unitized value and then use the length of that value to determine how many decimal places will be required.

BenjaminVanRyseghem added a commit that referenced this issue Oct 22, 2016

Merge pull request #219 from chrisnicola/patch-1
Fix #190 Allow abbreviation precision for < 4

gwynjudd added a commit to gwynjudd/numbro that referenced this issue Mar 28, 2017

Fix BenjaminVanRyseghem#190 Allow abbreviation precision for < 4
Currently for some reason when using abbreviations like `'0,0a`  you
can't specify the number of visible digits of precision for any value
less than 4. So while `'4,0a'` will change `1234567` to `1,234k` the
result of `'3,0a'` is `1m` instead of `1.23m` as expected.

This is primarily caused by a conditional that skips setting the
precision in the formatting.

This commit changes how the algorithm determines if decimal places will
be required and how many are required. We first compute the abbreviated
unitized value and then use the length of that value to determine how
many decimal places will be required.

gwynjudd added a commit to gwynjudd/numbro that referenced this issue Mar 28, 2017

Fix BenjaminVanRyseghem#190 Allow abbreviation precision for < 4
Currently for some reason when using abbreviations like `'0,0a`  you
can't specify the number of visible digits of precision for any value
less than 4. So while `'4,0a'` will change `1234567` to `1,234k` the
result of `'3,0a'` is `1m` instead of `1.23m` as expected.

This is primarily caused by a conditional that skips setting the
precision in the formatting.

This commit changes how the algorithm determines if decimal places will
be required and how many are required. We first compute the abbreviated
unitized value and then use the length of that value to determine how
many decimal places will be required.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment