I am trying to format a number as a currency and having problems. I’ve tried with both the default locale and a specific one (like below). The number is formatted in scientific notation nonetheless.
QLocale::setDefault( QLocale(QLocale::English, QLocale::UnitedStates) );
reportCost->setText( QString("$%L1").arg( cost ) );
The trouble is that as soon as I hit millions I get numbers like $1.6473e6 rather than $1,647,312. How can I fix this?
Also,is there really no way to format a currency at all in Qt, like positioning the symbol and proper negative representation?
I cannot test on Windows right now so I don’t know if this is Linux specific.
Unfortunately, the current implementation of
QLocalefalls short in a lot of these areas. See “QLocale: It’s about time (and dates, and languages, and …)” for an explanation of where this is headed in the future.For now, a quick-and-dirty solution would be:
If you need real localization, the ICU libraries might be helpful.