16 static_assert(
COIN > 1);
17 int64_t quotient = n /
COIN;
18 int64_t remainder = n %
COIN;
21 remainder = -remainder;
23 std::string str =
strprintf(
"%d.%08d", quotient, remainder);
27 for (
int i = str.size()-1; (str[i] ==
'0' &&
IsDigit(str[i-2])); --i)
30 str.erase(str.size()-nTrim, nTrim);
33 str.insert((
unsigned int)0, 1,
'-');
43 const std::string str =
TrimString(money_string);
50 const char* p = str.c_str();
56 int64_t nMult =
COIN / 10;
57 while (
IsDigit(*p) && (nMult > 0))
59 nUnits += nMult * (*p++ -
'0');
68 strWhole.insert(strWhole.end(), *p);
73 if (strWhole.size() > 10)
75 if (nUnits < 0 || nUnits >
COIN)
77 int64_t nWhole =
atoi64(strWhole);
static const CAmount COIN
constexpr bool IsDigit(char c)
Tests if the given character is a decimal digit.
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)
std::string FormatMoney(const CAmount n)
Money parsing/formatting utilities.
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.