16 int64_t n_abs = (n > 0 ? n : -n);
17 int64_t quotient = n_abs/
COIN;
18 int64_t remainder = n_abs%
COIN;
19 std::string str =
strprintf(
"%d.%08d", quotient, remainder);
23 for (
int i = str.size()-1; (str[i] ==
'0' &&
IsDigit(str[i-2])); --i)
26 str.erase(str.size()-nTrim, nTrim);
29 str.insert((
unsigned int)0, 1,
'-');
39 const std::string str =
TrimString(money_string);
46 const char* p = str.c_str();
52 int64_t nMult =
COIN / 10;
53 while (
IsDigit(*p) && (nMult > 0))
55 nUnits += nMult * (*p++ -
'0');
64 strWhole.insert(strWhole.end(), *p);
69 if (strWhole.size() > 10)
71 if (nUnits < 0 || nUnits >
COIN)
73 int64_t nWhole =
atoi64(strWhole);
74 CAmount nValue = nWhole*COIN + nUnits;
static const CAmount COIN
constexpr bool IsDigit(char c)
Tests if the given character is a decimal digit.
std::string FormatMoney(const CAmount &n)
Money parsing/formatting utilities.
bool ParseMoney(const std::string &money_string, CAmount &nRet)
Parse an amount denoted in full coins.
std::string TrimString(const std::string &str, const std::string &pattern=" \\\)
int64_t CAmount
Amount in satoshis (Can be negative)
int64_t atoi64(const std::string &str)
constexpr bool IsSpace(char c) noexcept
Tests if the given character is a whitespace character.
bool ValidAsCString(const std::string &str) noexcept
Check if a string does not contain any embedded NUL (\0) characters.