-
-
Notifications
You must be signed in to change notification settings - Fork 120
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
decimalFormatter does not always work with decimalSeparator=',' and thousandSeparator='.' #411
Comments
In my use case it works, but we are only using the I don't really have time to look into this, so if you could troubleshoot the problem, that would help. All the formatters end up using the |
As I said, I highly suspect that the reason for this is that we use this exact combination, with both values essentially swapped. I took a quick look at the unit tests, and I did not find this exact combination there, so this corner case could have gone unnoticed. For now, I've written a workaround specific to our project, since I'm also a bit short on time but I might get around to it in a couple of weeks. |
Quick investigation, this issue is happening only when both properties are used at the same time and works flawlessly when only 1 of the 2 is used. Not sure why yet though but that is the first thing I can see. |
Ok I found it, the code was basically cancelling each other when both were provided previous code export function decimalFormatted(...) {
// do we want to display our number with a custom separator in each thousand position
if (thousandSeparator) {
amount = thousandSeparatorFormatted(amount, thousandSeparator);
}
// when using a separator that is not a dot, replace it with the new separator
if (decimalSeparator !== '.') {
amount = amount.replace('.', decimalSeparator);
} The thousand separator was being changed by a decimal (.) but then was being cancelled by the second call of replace of decimal separator. I'm rewriting the code to instead just do a text split by the decimal and then combine integer + separator + decimal value and now it works for all cases. Considering the print screen below where
now it seems all fine, PR #415 is |
…ators fix(formatters): decimalSeparator & thousandSeparator work tgt, fix #411
Thank you very much for the fast response and even for fixing this so quickly! |
now shipped under new version Please upvote if you haven't already ⭐️ |
I'm submitting a Bug report
Your Environment
Describe the Bug
If we configure the FormatterOptions with
decimalSeparator: ','
andthousandSeparator: '.'
, the formatting does not take affect for values like1000.5
, while it will work for1.5
and for1000
Steps to Reproduce
Standard grid with a column with
FiledType.number
values, and aFormatters.decimalFormatter
,FormatterOptions with
decimalSeparator: ','
andthousandSeparator: '.'
.Expected Behavior
1000.5
, -> 1.000,51.5
-> 1,51000
-> 1.000Current Behavior
1000.5
, -> 1,000.51.5
-> 1,51000
-> 1.000Possible Solution
I strongly suspect that this is due to the fact that the config is exactly reversed to the defaults (decimalSeparator: '.' and thousandSeparator: ',').
Since both decimalFormatted and thousandSeparatorFormatted use string replacement and the bug only occurs if both functions need to run, my assumption is that the second function cancels out the replacement of the first one.
The text was updated successfully, but these errors were encountered: