23 static_assert(
COIN > 1);
24 int64_t quotient = n /
COIN;
25 int64_t remainder = n %
COIN;
28 remainder = -remainder;
30 std::string str =
strprintf(
"%d.%08d", quotient, remainder);
34 for (
int i = str.size()-1; (str[i] ==
'0' &&
IsDigit(str[i-2])); --i)
37 str.erase(str.size()-nTrim, nTrim);
40 str.insert(uint32_t{0}, 1,
'-');
45std::optional<CAmount>
ParseMoney(
const std::string& money_string)
50 const std::string str =
TrimString(money_string);
57 const char* p = str.c_str();
63 int64_t nMult =
COIN / 10;
64 while (
IsDigit(*p) && (nMult > 0))
66 nUnits += nMult * (*p++ -
'0');
75 strWhole.insert(strWhole.end(), *p);
80 if (strWhole.size() > 10)
82 if (nUnits < 0 || nUnits >
COIN)
84 int64_t nWhole = LocaleIndependentAtoi<int64_t>(strWhole);
bool MoneyRange(const CAmount &nValue)
int64_t CAmount
Amount in satoshis (Can be negative)
static constexpr CAmount COIN
The amount of satoshis in one BTC.
std::optional< CAmount > ParseMoney(const std::string &money_string)
Parse an amount denoted in full coins.
std::string FormatMoney(const CAmount n)
Money parsing/formatting utilities.
std::string TrimString(std::string_view str, std::string_view pattern=" \f\n\r\t\v")
bool ContainsNoNUL(std::string_view str) noexcept
Check if a string does not contain any embedded NUL (\0) characters.
constexpr bool IsDigit(char c)
Tests if the given character is a decimal digit.
constexpr bool IsSpace(char c) noexcept
Tests if the given character is a whitespace character.