From f7020a31c02f4d1e5a46ce2ea20e38751f9afeed Mon Sep 17 00:00:00 2001 From: Dan Cape Date: Tue, 29 Sep 2015 13:57:40 -0400 Subject: Add ability to specify precision of float/double currency strings Added a new overload function that allows the developer to specify the desired precision. Until 6.0, it will require the symbol and precision to be passed to it. Once Qt is at version 6.0, it will replace the overload function that requires a value and optionally a symbol. [ChangeLog][QtCore][QLocale] Added an overload for toCurrencyString() that allows the decimal precision to be specified. Change-Id: I1fb7dde3583f46de2ed20ec2a7abaeca23a903ef Task-number: QTBUG-46595 Reviewed-by: Thiago Macieira --- src/corelib/tools/qlocale.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'src/corelib/tools/qlocale.cpp') diff --git a/src/corelib/tools/qlocale.cpp b/src/corelib/tools/qlocale.cpp index bbba18fa27..af2522acc3 100644 --- a/src/corelib/tools/qlocale.cpp +++ b/src/corelib/tools/qlocale.cpp @@ -3460,11 +3460,22 @@ QString QLocale::toCurrencyString(qulonglong value, const QString &symbol) const return format.arg(str, sym); } +#if QT_VERSION < QT_VERSION_CHECK(6,0,0) /*! \since 4.8 \overload */ QString QLocale::toCurrencyString(double value, const QString &symbol) const +{ + return toCurrencyString(value, symbol, d->m_data->m_currency_digits); +} +#endif + +/*! + \since 5.7 + \overload + */ +QString QLocale::toCurrencyString(double value, const QString &symbol, int precision) const { #ifndef QT_NO_SYSTEMLOCALE if (d->m_data == systemData()) { @@ -3482,7 +3493,7 @@ QString QLocale::toCurrencyString(double value, const QString &symbol) const size = data->m_currency_negative_format_size; value = -value; } - QString str = toString(value, 'f', d->m_data->m_currency_digits); + QString str = toString(value, 'f', precision == -1 ? d->m_data->m_currency_digits : precision); QString sym = symbol.isNull() ? currencySymbol() : symbol; if (sym.isEmpty()) sym = currencySymbol(QLocale::CurrencyIsoCode); -- cgit v1.2.3