 |
Bitcoin Core
22.99.0
P2P Digital Currency
|
Go to the documentation of this file.
19 static_assert(
COIN > 1);
20 int64_t quotient = n /
COIN;
21 int64_t remainder = n %
COIN;
24 remainder = -remainder;
26 std::string str =
strprintf(
"%d.%08d", quotient, remainder);
30 for (
int i = str.size()-1; (str[i] ==
'0' &&
IsDigit(str[i-2])); --i)
33 str.erase(str.size()-nTrim, nTrim);
36 str.insert((
unsigned int)0, 1,
'-');
41 std::optional<CAmount>
ParseMoney(
const std::string& money_string)
46 const std::string str =
TrimString(money_string);
53 const char* p = str.c_str();
59 int64_t nMult =
COIN / 10;
60 while (
IsDigit(*p) && (nMult > 0))
62 nUnits += nMult * (*p++ -
'0');
71 strWhole.insert(strWhole.end(), *p);
76 if (strWhole.size() > 10)
78 if (nUnits < 0 || nUnits >
COIN)
80 int64_t nWhole = LocaleIndependentAtoi<int64_t>(strWhole);
bool MoneyRange(const CAmount &nValue)
std::string TrimString(const std::string &str, const std::string &pattern=" \f\n\r\t\v")
bool ValidAsCString(const std::string &str) noexcept
Check if a string does not contain any embedded NUL (\0) characters.
constexpr bool IsSpace(char c) noexcept
Tests if the given character is a whitespace character.
int64_t CAmount
Amount in satoshis (Can be negative)
constexpr bool IsDigit(char c)
Tests if the given character is a decimal digit.
std::optional< CAmount > ParseMoney(const std::string &money_string)
Parse an amount denoted in full coins.
static constexpr CAmount COIN
The amount of satoshis in one BTC.
std::string FormatMoney(const CAmount n)
Money parsing/formatting utilities.