On 30/05/14 16:44, Thomas Baumgart wrote:
Allen,
On Friday 30 May 2014 14:00:02 Allan wrote:
[...]
On 30/05/14 13:10, Thomas Baumgart wrote:
I need to convert a monetary string to double in order to test if it is
zero, or empty. Previously, when there was either a valid debit or
credit value, I didn't take the other field into account. This bug was
from a file where instead of the 'other' field being empty, it contained
a zero value. I could replace the zero with empty, but I've been trying
to detect it to warn the user before clearing it.
Yep, I followed that discussion.
QLocale::toCurrencyString or QLocale::toString(loc->readMoney won't work
as they are not static, so I had to provide an object. This goes back
to my original problem, though. I need to create a default QLocale, but
I can't do that as I don't know what country I'm running in. I can get
the KLocale locale setting, but can't convert that to a QLocale.
Hmm, that still leaves a problem: you never know if the file the user has
matches his locale. I've seen banks in Germany delivering CSV files with a dot
as decimal symbol while we usually use a comma for that purpose. Since the
same applies to QIF, I once wrote
Ah, that's interesting. I'll need to have a think about that, as it may
impact something else I've done. Apart from the unexpected zeroes,
another issue involved is that sometimes a value has no decimal point or
decimal part and I have to add those. I think I've used the locale
decimal, but the user actually gets to choose the decimal he wants, so I
really need to use that. Slight problem there is that he doesn't get to
choose until a bit later. Unless I bring forward my intention to
identify the decimal actually in the file......
void MyMoneyQifProfile::scanNumeric(const QString& txt, QChar& decimal, QChar&
thousands) const
which scans the string to determine decimal and thousand separator characters.
Once you have that, you could use regular Alkimia for what you want to do.
Here's how:
QString inputVal; // your unknown input data
QChar decimal('.'), thousands; // make the dot the default
scanNumeric(inputVal, decimal, thousands);
if(AlkValue(inputVal, decimal) == AlkValue(0)) {
}
Since scanNumeric is not static either, simply make a copy of it in your
class.
Apart from what I just wrote above, I already have my own routine to
check and verify the decimal points after the user has made his choice.
Ho hum... This fix is already much more complicated, or bigger anyway,
than I expected. Thanks for the above help as well, Thomas.
Allan
_______________________________________________
KMyMoney-devel mailing list
KMyMoney-devel@kde.org
https://mail.kde.org/mailman/listinfo/kmymoney-devel