TickerWidget: Format fiat currency using locale

This commit is contained in:
tobtoht
2020-11-24 23:10:50 +01:00
parent 9d781d1b57
commit 4201167477
4 changed files with 21 additions and 13 deletions
+15
View File
@@ -581,4 +581,19 @@ QString Utils::formatBytes(quint64 bytes)
_data = 0;
return QString("%1 %2").arg(QString::number(_data, 'f', 1), sizes[i]);
}
QString Utils::amountToCurrencyString(double amount, const QString &currencyCode) {
QLocale locale;
QList<QLocale> allLocales = QLocale::matchingLocales(QLocale::AnyLanguage, QLocale::AnyScript, QLocale::AnyCountry);
for (const auto& locale_: allLocales) {
if (locale_.currencySymbol(QLocale::CurrencyIsoCode) == currencyCode) {
locale = locale_;
}
}
if (currencyCode == "USD")
return locale.toCurrencyString(amount, "$");
return locale.toCurrencyString(amount);
}