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

remove trailing zeros but keep at least N decimal positions while using thousandSeperator #611

Open
GTadeon opened this issue Feb 10, 2022 · 1 comment

Comments

@GTadeon
Copy link

GTadeon commented Feb 10, 2022

So say that I have NumberFormat element with the following props:

isNumericString:false
thousandSeparator:true
decimalsScale: 5
fixedDecimalScale:true

and I want to be able to cut trailing zeros in the decimal part such that it always displays at least two zeros in the decimal part (which is something you would see in case you have decimalScale:2 for example), but cuts the rest, bearing in mind that max allowed decimals is 5. How should I go about it ?

so desired output would be:
1 => 1.00
1234 => 1,234.00
123.1234 => 123.1234
12345678.90 => 123,456,78.90
12345678.90000 => 123,456,78.90
12345678.90100 => 123,456,78.901
(and entering more than 5 decimals jsut wouldn't be allowed)

I know for the custom format, but what if I don't want to reinvent the wheel and add thousandSeperator and fixedDecimalScale props' logic by myself (because yeah, I'm losing those two if I go for custom formatting)

how should I go about this ?

maybe adding cutTrailingZeros (and providing the int amount of trailing zeros to be cut , if any found) prop in the future , for something like this, would be a good idea?

@GTadeon
Copy link
Author

GTadeon commented Feb 10, 2022

implemented, gonna open up a PR for this

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

No branches or pull requests

1 participant