You can remove the thousands separators from the string before passing it to
strtod
.
If you want to store the value as
CURRENCY
in the database you may also write your own parser using integers.
A possible solution (compiled but not fully tested):
bool StrToCy(CY& cy, char *p)
{
bool bNeg = false;
char *pStop;
cy.int64 = 0;
LONGLONG l1 = 0;
LONGLONG l2 = 0;
while (*p == ' ')
p++;
if (*p == '-')
{
bNeg = true;
p++;
}
else if (*p == '+')
p++;
while (*p == ',' || isdigit(*p))
{
if (isdigit(*p))
l1 = l1 * 10LL + (*p - '0');
p++;
}
if (*p == '.')
{
l2 = strtoul(++p, &pStop, 10);
int digits = (int)(pStop - p);
while (digits < 4)
{
l2 *= 10LL;
++digits;
}
}
else
pStop = p;
if (bNeg)
l1 = -l1;
if (*pStop <= ' ' && l1 < (LLONG_MAX / 10000LL) && l2 < 10000LL)
{
cy.int64 = l1 * 10000LL + l2;
return true;
}
return false;
}