19 strprintf(
"%d.%0*d", amt_abs / currency.baseunit, currency.decimals,
20 (amt_abs % currency.baseunit) / currency.subunit);
24 for (
int i = str.size() - 1; (str[i] ==
'0' &&
IsDigit(str[i - 2])); --i) {
28 str.erase(str.size() - nTrim, nTrim);
32 str.insert((
unsigned int)0, 1,
'-');
41 const std::string str =
TrimString(money_string);
49 const char *p = str.c_str();
53 Amount nMult = currency.baseunit / 10;
55 nUnits += (*p++ -
'0') * nMult;
66 strWhole.insert(strWhole.end(), *p);
75 assert(currency.decimals <= 18);
78 if (strWhole.size() > (
size_t(18) - currency.decimals)) {
81 if (nUnits <
Amount::zero() || nUnits > currency.baseunit) {
87 nRet = nWhole +
Amount(nUnits);
std::string FormatMoney(const Amount amt)
Do not use these functions to represent or parse monetary amounts to or from JSON but use AmountFromV...
bool ParseMoney(const std::string &money_string, Amount &nRet)
Parse an amount denoted in full coins.
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.
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.
static constexpr Amount zero() noexcept
static const Currency & get()
int64_t atoi64(const std::string &str)