`toCurrencyString` multiplies result by 10 when target decimal separator is comma
nizioleque opened this issue · 5 comments
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,
);
@nizioleque what if you use Period as thousand separator without your workaround mention above? is it multiplied by 10 also?
@fahami Yes, you can see this in the examples I provided.
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
thank you @nizioleque for the walkaround! having the same issue here..
waiting for the fix!
any fixes ? this issue became like a horror