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

toCurrencyString multiplies result by 10 when target decimal separator is comma #116

Closed
nizioleque opened this issue Jan 8, 2023 · 5 comments

Comments

@nizioleque
Copy link

Example code:

(1.0).toCurrencyString(
  thousandSeparator: ThousandSeparator.Period,
);

returns "10,00" instead of expected "1,00".

The same happens with the following code:

toCurrencyString(
  (1.0).toString(),
  thousandSeparator: ThousandSeparator.Period,
);

which to me also seems like a bug, but maybe this is the expected behavior? Could you please mention the expected input for this function in the documentation?

I have found a temporary workaround, but I would appreciate a fix :)

Here is my workaround, if anyone needs it:

// example input
ThousandSeparator targetThousandSeparator = ThousandSeparator.Period;
double value = 1.0;

// workaround
String valueString = value.toString();
if ([ThousandSeparator.Period, ThousandSeparator.SpaceAndCommaMantissa].contains(targetThousandSeparator)) {
  valueString = valueString.replaceFirst('.', ',');
}

return toCurrencyString(
  valueString,
  thousandSeparator: targetThousandSeparator,
);
@fahami
Copy link

fahami commented Jan 16, 2023

@nizioleque what if you use Period as thousand separator without your workaround mention above? is it multiplied by 10 also?

@nizioleque
Copy link
Author

@fahami Yes, you can see this in the examples I provided.

@alod2019
Copy link

alod2019 commented Feb 1, 2023

14.35.toCurrencyString(thousandSeparator: ThousandSeparator.SpaceAndCommaMantissa)
gives 1 435,00
so it just removes the dot when processing "14.35" string but not multilpies anything

@turtlepile
Copy link

thank you @nizioleque for the walkaround! having the same issue here..

waiting for the fix!

@eldarkk
Copy link

eldarkk commented Mar 17, 2023

any fixes ? this issue became like a horror

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

5 participants