aboutsummaryrefslogtreecommitdiff
path: root/util.cpp
diff options
context:
space:
mode:
authorGavin Andresen <gavinandresen@gmail.com>2011-02-23 16:26:15 -0500
committerGavin Andresen <gavinandresen@gmail.com>2011-02-23 16:26:15 -0500
commitb0ad55a08a32832709f3b298b588577422071a93 (patch)
tree13aab0a1dafc20fcf5ceaa666ef4bfac222606e9 /util.cpp
parent87504abb070cf9df4b2bf24787ce14643df9b07d (diff)
ParseMoney: allow full precision
Diffstat (limited to 'util.cpp')
-rw-r--r--util.cpp20
1 files changed, 8 insertions, 12 deletions
diff --git a/util.cpp b/util.cpp
index 5f6f10a329..8518e27975 100644
--- a/util.cpp
+++ b/util.cpp
@@ -343,7 +343,7 @@ bool ParseMoney(const string& str, int64& nRet)
bool ParseMoney(const char* pszIn, int64& nRet)
{
string strWhole;
- int64 nCents = 0;
+ int64 nUnits = 0;
const char* p = pszIn;
while (isspace(*p))
p++;
@@ -354,11 +354,11 @@ bool ParseMoney(const char* pszIn, int64& nRet)
if (*p == '.')
{
p++;
- if (isdigit(*p))
+ int64 nMult = CENT*10;
+ while (isdigit(*p) && (nMult > 0))
{
- nCents = 10 * (*p++ - '0');
- if (isdigit(*p))
- nCents += (*p++ - '0');
+ nUnits += nMult * (*p++ - '0');
+ nMult /= 10;
}
break;
}
@@ -373,15 +373,11 @@ bool ParseMoney(const char* pszIn, int64& nRet)
return false;
if (strWhole.size() > 14)
return false;
- if (nCents < 0 || nCents > 99)
+ if (nUnits < 0 || nUnits > COIN)
return false;
int64 nWhole = atoi64(strWhole);
- int64 nPreValue = nWhole * 100 + nCents;
- int64 nValue = nPreValue * CENT;
- if (nValue / CENT != nPreValue)
- return false;
- if (nValue / COIN != nWhole)
- return false;
+ int64 nValue = nWhole*COIN + nUnits;
+
nRet = nValue;
return true;
}