diff options
author | Konstantin Ritt <ritt.ks@gmail.com> | 2012-11-23 11:45:01 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2012-11-23 22:58:59 +0100 |
commit | 3c0ac5208111c85c405ba1ee6ce3189a6c4e1236 (patch) | |
tree | 18ed197d3e40115282534c688aa1a361467f76bc | |
parent | 86bbe5a43a568b9d0136f8e72f3842419ae39ab2 (diff) |
QLocale: Fix toCurrencyString() didn't respect group separator option
Change-Id: Icda43d71d600d77fe1ed4fcde1ef4478ef29c1d5
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Reviewed-by: Denis Dzyubenko <denis@ddenis.info>
-rw-r--r-- | src/corelib/tools/qlocale.cpp | 7 | ||||
-rw-r--r-- | tests/auto/corelib/tools/qlocale/tst_qlocale.cpp | 36 |
2 files changed, 24 insertions, 19 deletions
diff --git a/src/corelib/tools/qlocale.cpp b/src/corelib/tools/qlocale.cpp index 2f0e4970b0..c49b3e0fff 100644 --- a/src/corelib/tools/qlocale.cpp +++ b/src/corelib/tools/qlocale.cpp @@ -3253,7 +3253,7 @@ QString QLocale::toCurrencyString(qlonglong value, const QString &symbol) const size = d->m_data->m_currency_negative_format_size; value = -value; } - QString str = d->longLongToString(value); + QString str = toString(value); QString sym = symbol.isNull() ? currencySymbol() : symbol; if (sym.isEmpty()) sym = currencySymbol(QLocale::CurrencyIsoCode); @@ -3278,7 +3278,7 @@ QString QLocale::toCurrencyString(qulonglong value, const QString &symbol) const const QLocaleData *data = this->d->m_data; quint8 idx = data->m_currency_format_idx; quint8 size = data->m_currency_format_size; - QString str = d->unsLongLongToString(value); + QString str = toString(value); QString sym = symbol.isNull() ? currencySymbol() : symbol; if (sym.isEmpty()) sym = currencySymbol(QLocale::CurrencyIsoCode); @@ -3308,8 +3308,7 @@ QString QLocale::toCurrencyString(double value, const QString &symbol) const size = data->m_currency_negative_format_size; value = -value; } - QString str = d->doubleToString(value, d->m_data->m_currency_digits, - QLocalePrivate::DFDecimal); + QString str = toString(value, 'f', d->m_data->m_currency_digits); QString sym = symbol.isNull() ? currencySymbol() : symbol; if (sym.isEmpty()) sym = currencySymbol(QLocale::CurrencyIsoCode); diff --git a/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp b/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp index 1756fec35b..911187da53 100644 --- a/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp +++ b/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp @@ -1678,25 +1678,31 @@ void tst_QLocale::standaloneMonthName() void tst_QLocale::currency() { const QLocale c(QLocale::C); - QCOMPARE(c.toCurrencyString(qulonglong(1234)), QString("1234")); - QCOMPARE(c.toCurrencyString(qlonglong(-1234)), QString("-1234")); - QCOMPARE(c.toCurrencyString(double(1234.56)), QString("1234.56")); - QCOMPARE(c.toCurrencyString(double(-1234.56)), QString("-1234.56")); + QCOMPARE(c.toCurrencyString(qulonglong(1234)), QString("1,234")); + QCOMPARE(c.toCurrencyString(qlonglong(-1234)), QString("-1,234")); + QCOMPARE(c.toCurrencyString(double(1234.56)), QString("1,234.56")); + QCOMPARE(c.toCurrencyString(double(-1234.56)), QString("-1,234.56")); + + const QLocale en_US("en_US"); + QCOMPARE(en_US.toCurrencyString(qulonglong(1234)), QString("$1,234")); + QCOMPARE(en_US.toCurrencyString(qlonglong(-1234)), QString("($1,234)")); + QCOMPARE(en_US.toCurrencyString(double(1234.56)), QString("$1,234.56")); + QCOMPARE(en_US.toCurrencyString(double(-1234.56)), QString("($1,234.56)")); const QLocale ru_RU("ru_RU"); - QCOMPARE(ru_RU.toCurrencyString(qulonglong(1234)), QString::fromUtf8("1234\xc2\xa0\xd1\x80\xd1\x83\xd0\xb1.")); - QCOMPARE(ru_RU.toCurrencyString(qlonglong(-1234)), QString::fromUtf8("-1234\xc2\xa0\xd1\x80\xd1\x83\xd0\xb1.")); - QCOMPARE(ru_RU.toCurrencyString(double(1234.56)), QString::fromUtf8("1234,56\xc2\xa0\xd1\x80\xd1\x83\xd0\xb1.")); - QCOMPARE(ru_RU.toCurrencyString(double(-1234.56)), QString::fromUtf8("-1234,56\xc2\xa0\xd1\x80\xd1\x83\xd0\xb1.")); + QCOMPARE(ru_RU.toCurrencyString(qulonglong(1234)), QString::fromUtf8("1" "\xc2\xa0" "234\xc2\xa0\xd1\x80\xd1\x83\xd0\xb1.")); + QCOMPARE(ru_RU.toCurrencyString(qlonglong(-1234)), QString::fromUtf8("-1" "\xc2\xa0" "234\xc2\xa0\xd1\x80\xd1\x83\xd0\xb1.")); + QCOMPARE(ru_RU.toCurrencyString(double(1234.56)), QString::fromUtf8("1" "\xc2\xa0" "234,56\xc2\xa0\xd1\x80\xd1\x83\xd0\xb1.")); + QCOMPARE(ru_RU.toCurrencyString(double(-1234.56)), QString::fromUtf8("-1" "\xc2\xa0" "234,56\xc2\xa0\xd1\x80\xd1\x83\xd0\xb1.")); const QLocale de_DE("de_DE"); - QCOMPARE(de_DE.toCurrencyString(qulonglong(1234)), QString::fromUtf8("1234\xc2\xa0\xe2\x82\xac")); - QCOMPARE(de_DE.toCurrencyString(qulonglong(1234), QLatin1String("BAZ")), QString::fromUtf8("1234\xc2\xa0" "BAZ")); - QCOMPARE(de_DE.toCurrencyString(qlonglong(-1234)), QString::fromUtf8("-1234\xc2\xa0\xe2\x82\xac")); - QCOMPARE(de_DE.toCurrencyString(qlonglong(-1234), QLatin1String("BAZ")), QString::fromUtf8("-1234\xc2\xa0" "BAZ")); - QCOMPARE(de_DE.toCurrencyString(double(1234.56)), QString::fromUtf8("1234,56\xc2\xa0\xe2\x82\xac")); - QCOMPARE(de_DE.toCurrencyString(double(-1234.56)), QString::fromUtf8("-1234,56\xc2\xa0\xe2\x82\xac")); - QCOMPARE(de_DE.toCurrencyString(double(-1234.56), QLatin1String("BAZ")), QString::fromUtf8("-1234,56\xc2\xa0" "BAZ")); + QCOMPARE(de_DE.toCurrencyString(qulonglong(1234)), QString::fromUtf8("1.234\xc2\xa0\xe2\x82\xac")); + QCOMPARE(de_DE.toCurrencyString(qulonglong(1234), QLatin1String("BAZ")), QString::fromUtf8("1.234\xc2\xa0" "BAZ")); + QCOMPARE(de_DE.toCurrencyString(qlonglong(-1234)), QString::fromUtf8("-1.234\xc2\xa0\xe2\x82\xac")); + QCOMPARE(de_DE.toCurrencyString(qlonglong(-1234), QLatin1String("BAZ")), QString::fromUtf8("-1.234\xc2\xa0" "BAZ")); + QCOMPARE(de_DE.toCurrencyString(double(1234.56)), QString::fromUtf8("1.234,56\xc2\xa0\xe2\x82\xac")); + QCOMPARE(de_DE.toCurrencyString(double(-1234.56)), QString::fromUtf8("-1.234,56\xc2\xa0\xe2\x82\xac")); + QCOMPARE(de_DE.toCurrencyString(double(-1234.56), QLatin1String("BAZ")), QString::fromUtf8("-1.234,56\xc2\xa0" "BAZ")); const QLocale system = QLocale::system(); QVERIFY(system.toCurrencyString(1, QLatin1String("FOO")).contains(QLatin1String("FOO"))); |