Changeset View
Changeset View
Standalone View
Standalone View
src/util/moneystr.cpp
Show All 12 Lines | std::string FormatMoney(const Amount amt) { | ||||
// Note: not using straight sprintf here because we do NOT want localized | // Note: not using straight sprintf here because we do NOT want localized | ||||
// number formatting. | // number formatting. | ||||
Amount amt_abs = amt > Amount::zero() ? amt : -amt; | Amount amt_abs = amt > Amount::zero() ? amt : -amt; | ||||
std::string str = | std::string str = | ||||
strprintf("%d.%08d", amt_abs / COIN, (amt_abs % COIN) / SATOSHI); | strprintf("%d.%08d", amt_abs / COIN, (amt_abs % COIN) / SATOSHI); | ||||
// Right-trim excess zeros before the decimal point: | // Right-trim excess zeros before the decimal point: | ||||
int nTrim = 0; | int nTrim = 0; | ||||
for (int i = str.size() - 1; (str[i] == '0' && isdigit(str[i - 2])); --i) { | for (int i = str.size() - 1; (str[i] == '0' && IsDigit(str[i - 2])); --i) { | ||||
++nTrim; | ++nTrim; | ||||
} | } | ||||
if (nTrim) { | if (nTrim) { | ||||
str.erase(str.size() - nTrim, nTrim); | str.erase(str.size() - nTrim, nTrim); | ||||
} | } | ||||
if (amt < Amount::zero()) { | if (amt < Amount::zero()) { | ||||
str.insert((unsigned int)0, 1, '-'); | str.insert((unsigned int)0, 1, '-'); | ||||
Show All 11 Lines | bool ParseMoney(const char *pszIn, Amount &nRet) { | ||||
const char *p = pszIn; | const char *p = pszIn; | ||||
while (IsSpace(*p)) { | while (IsSpace(*p)) { | ||||
p++; | p++; | ||||
} | } | ||||
for (; *p; p++) { | for (; *p; p++) { | ||||
if (*p == '.') { | if (*p == '.') { | ||||
p++; | p++; | ||||
Amount nMult = COIN / 10; | Amount nMult = COIN / 10; | ||||
while (isdigit(*p) && (nMult > Amount::zero())) { | while (IsDigit(*p) && (nMult > Amount::zero())) { | ||||
nUnits += (*p++ - '0') * nMult; | nUnits += (*p++ - '0') * nMult; | ||||
nMult /= 10; | nMult /= 10; | ||||
} | } | ||||
break; | break; | ||||
} | } | ||||
if (IsSpace(*p)) { | if (IsSpace(*p)) { | ||||
break; | break; | ||||
} | } | ||||
if (!isdigit(*p)) { | if (!IsDigit(*p)) { | ||||
return false; | return false; | ||||
} | } | ||||
strWhole.insert(strWhole.end(), *p); | strWhole.insert(strWhole.end(), *p); | ||||
} | } | ||||
for (; *p; p++) { | for (; *p; p++) { | ||||
if (!IsSpace(*p)) { | if (!IsSpace(*p)) { | ||||
return false; | return false; | ||||
} | } | ||||
Show All 14 Lines |