QLocale toCurrencyString ignores precision
(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:
On 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
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 ...