Mercurial > hg > bitcoin
changeset 454:09c504f1f58f draft
ParseMoney: allow full precision
author | Gavin Andresen <gavinandresen@gmail.com> |
---|---|
date | Wed, 23 Feb 2011 16:26:15 -0500 |
parents | a258e81cfdea |
children | caf8330369a9 7ab9ca18ba56 |
files | util.cpp |
diffstat | 1 files changed, 8 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/util.cpp +++ b/util.cpp @@ -343,7 +343,7 @@ 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 @@ 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 @@ 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; }