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

Currency conversion floating point hotfix #1569

Merged
merged 4 commits into from
Aug 27, 2024
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,10 @@ fun BigDecimal.convertFiatDecimalToFiatString(
monetarySeparators: MonetarySeparators,
includeSymbols: Boolean = true
): String {
val numberFormat =
if (includeSymbols) {
NumberFormat.getCurrencyInstance(locale)
} else {
NumberFormat.getInstance(locale)
}
val numberFormat = NumberFormat.getCurrencyInstance(locale)

return numberFormat.apply {
if (includeSymbols) {
currency = fiatCurrency
}

currency = fiatCurrency
roundingMode = RoundingMode.HALF_EVEN
if (this is DecimalFormat) {
decimalFormatSymbols.apply {
Expand All @@ -95,5 +87,11 @@ fun BigDecimal.convertFiatDecimalToFiatString(
}
}
}
}.format(this)
}.format(this).let {
if (includeSymbols) {
it
} else {
it.replace(fiatCurrency.symbol, "")
Copy link
Contributor

@daira daira Aug 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't remove spaces from the output. For example, the currency format for the CANADA_FRENCH locale is something like "1,23\u00A0$", and so the "\u00A0" (non-breaking space) won't be removed.

Suggested change
it.replace(fiatCurrency.symbol, "")
it.replace(fiatCurrency.symbol, "").strip()

(see java.lang.String.strip).

}
}
}
Loading