summaryrefslogtreecommitdiffstats
path: root/src/corelib
diff options
context:
space:
mode:
authorDan Cape <dcape@qnx.com>2015-09-29 13:57:40 -0400
committerDan Cape <dcape@qnx.com>2016-01-13 06:35:14 +0000
commitf7020a31c02f4d1e5a46ce2ea20e38751f9afeed (patch)
tree69dfada0c808c55684081728add28666525a043e /src/corelib
parent68e915c623613d32526be1a7c0d9b6b0d8322209 (diff)
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 <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib')
-rw-r--r--src/corelib/tools/qlocale.cpp13
-rw-r--r--src/corelib/tools/qlocale.h14
2 files changed, 23 insertions, 4 deletions
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,12 +3460,23 @@ 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()) {
QSystemLocale::CurrencyToStringArgument arg(value, symbol);
@@ -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);
diff --git a/src/corelib/tools/qlocale.h b/src/corelib/tools/qlocale.h
index b10dee509f..1f4083950c 100644
--- a/src/corelib/tools/qlocale.h
+++ b/src/corelib/tools/qlocale.h
@@ -963,8 +963,18 @@ public:
inline QString toCurrencyString(ushort, const QString &symbol = QString()) const;
inline QString toCurrencyString(int, const QString &symbol = QString()) const;
inline QString toCurrencyString(uint, const QString &symbol = QString()) const;
+#if QT_VERSION >= QT_VERSION_CHECK(6,0,0)
+ QString toCurrencyString(double, const QString &symbol = QString(), int precision = -1) const;
+ inline QString toCurrencyString(float i, const QString &symbol = QString(), int precision = -1) const
+ { return toCurrencyString(double(i), symbol, precision); }
+#else
QString toCurrencyString(double, const QString &symbol = QString()) const;
- inline QString toCurrencyString(float, const QString &symbol = QString()) const;
+ QString toCurrencyString(double, const QString &symbol, int precision) const;
+ inline QString toCurrencyString(float i, const QString &symbol = QString()) const
+ { return toCurrencyString(double(i), symbol); }
+ inline QString toCurrencyString(float i, const QString &symbol, int precision) const
+ { return toCurrencyString(double(i), symbol, precision); }
+#endif
QStringList uiLanguages() const;
@@ -1020,8 +1030,6 @@ inline QString QLocale::toCurrencyString(int i, const QString &symbol) const
{ return toCurrencyString(qlonglong(i), symbol); }
inline QString QLocale::toCurrencyString(uint i, const QString &symbol) const
{ return toCurrencyString(qulonglong(i), symbol); }
-inline QString QLocale::toCurrencyString(float i, const QString &symbol) const
-{ return toCurrencyString(double(i), symbol); }
#ifndef QT_NO_DATASTREAM
Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QLocale &);