[Kmymoney-devel] Another locale puzzle - CSV Importer
Thomas Baumgart
thb at net-bembel.de
Fri May 30 15:44:31 UTC 2014
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
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.
Does that make sense?
--
Regards
Thomas Baumgart
GPG-FP: E55E D592 F45F 116B 8429 4F99 9C59 DB40 B75D D3BA
-------------------------------------------------------------
A sufficient amount of googling is indistinguishable
from actual knowledge. -- unknown source
-------------------------------------------------------------
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 225 bytes
Desc: This is a digitally signed message part.
URL: <http://mail.kde.org/pipermail/kmymoney-devel/attachments/20140530/1081788e/attachment.sig>
More information about the KMyMoney-devel
mailing list