Solved QLocale toCurrencyString ignores precision
-
Hi,
(QT 5.10.1 MSVC 2015 32 bit)
I'm not sure if I'm missing something here, but the results I get using the toCurrencyString overload with a double and precision completely ignore the precision that is set.
E.g. With the example below, from a double of 1234567.12 the result I would expect is €1,234,567 but the result I actually get (€1,234,567.12) always has a precision of 2.
QString szCurSym = QLocale("es_ES").currencySymbol(); double dblTestVal=1234567.12; QString szResult=QLocale().toCurrencyString(dblTestVal,szCurSym,0); //precision ignored
Thanks in advance.
-
That's because you are using the system locale (i.e.
QLocale()
) it is documented even if a bit obscure:
http://doc.qt.io/qt-5/qlocale.html#systemOn Windows and Mac, this locale will use the decimal[...] formats specified in the system configuration panel.
QLocale(QLocale().language(),QLocale().country()).toCurrencyString(dblTestVal,szCurSym,0);
will actually use the precision -
@VRonin said in QLocale toCurrencyString ignores precision:
QLocale(QLocale().language(),QLocale().country()).toCurrencyString(dblTestVal,szCurSym,0);
Thanks, that works. You would think that specifically setting the precision would take precedence. Maybe it would be better worded as ... the locale will always use ...