QLocale toCurrencyString() reverse
-
-
Hi,
You can try with something like:
QString currencyString = locale.toCurrencyString(1000.55); QString cleanedString = currencyString.remove(locale.currencySymbol()).trimmed(); qDebug() << locale.toDouble(cleanedString);
Hope it helps
-
This post is deleted!
-
I would like to know how to convert string with currency (i.e. obtained from QLocale().toCurrencyString(value)) back to double value.
Note that in some OS currency string is sometimes "$1,000.00" or can be "1.000,00 €". How do I convert it to double? -
Hi,
You can try with something like:
QString currencyString = locale.toCurrencyString(1000.55); QString cleanedString = currencyString.remove(locale.currencySymbol()).trimmed(); qDebug() << locale.toDouble(cleanedString);
Hope it helps
-
@Borzh Do you really use floating point data types for financial calculations?!
Never do this, because floating point numbers are not exact.
Use integer types and sore the values as Cent: 1$ = 100Cent