[core][android][darwin] Move number format to i18n
This commit is contained in:
26
platform/qt/src/number_format.cpp
Normal file
26
platform/qt/src/number_format.cpp
Normal file
@@ -0,0 +1,26 @@
|
||||
#include <mbgl/util/platform.hpp>
|
||||
|
||||
#include <QLocale>
|
||||
#include <QString>
|
||||
|
||||
namespace mbgl {
|
||||
namespace platform {
|
||||
|
||||
std::string formatNumber(double number, const std::string& localeId, const std::string& currency,
|
||||
uint8_t minFractionDigits, uint8_t maxFractionDigits) {
|
||||
|
||||
QString formatted;
|
||||
// Qt Locale::toString() API takes only one precision argument
|
||||
(void)minFractionDigits;
|
||||
QLocale locale = QLocale(QString::fromStdString(localeId));
|
||||
|
||||
if (!currency.empty()) {
|
||||
formatted = locale.toCurrencyString(number);
|
||||
} else {
|
||||
formatted = locale.toString(number, 'f', maxFractionDigits);
|
||||
}
|
||||
return formatted.toStdString();
|
||||
}
|
||||
|
||||
} // namespace platform
|
||||
} // namespace mbgl
|
||||
Reference in New Issue
Block a user