17 int64_t quotient = amt / currency.baseunit;
18 int64_t remainder = (amt % currency.baseunit) / currency.subunit;
21 remainder = -remainder;
24 strprintf(
"%d.%0*d", quotient, currency.decimals, remainder);
28 for (
int i = str.size() - 1; (str[i] ==
'0' &&
IsDigit(str[i - 2])); --i) {
32 str.erase(str.size() - nTrim, nTrim);
36 str.insert((
unsigned int)0, 1,
'-');
53 const char *p = str.c_str();
57 Amount nMult = currency.baseunit / 10;
59 nUnits += (*p++ -
'0') * nMult;
70 strWhole.insert(strWhole.end(), *p);
79 assert(currency.decimals <= 18);
82 if (strWhole.size() > (
size_t(18) - currency.decimals)) {
85 if (nUnits <
Amount::zero() || nUnits > currency.baseunit) {
90 LocaleIndependentAtoi<int64_t>(strWhole) * currency.baseunit;
92 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.
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.
static constexpr Amount zero() noexcept
static const Currency & get()