1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
/*!
| Money parsing/formatting utilities.
|
*/
crate::ix!();
//-------------------------------------------[.cpp/bitcoin/src/util/moneystr.h]
//-------------------------------------------[.cpp/bitcoin/src/util/moneystr.cpp]
/**
| Do not use these functions to represent
| or parse monetary amounts to or from
|
| JSON but use AmountFromValue and ValueFromAmount
| for that.
|
*/
pub fn format_money(n: Amount) -> String {
todo!();
/*
// Note: not using straight sprintf here because we do NOT want
// localized number formatting.
const_assert(COIN > 1);
int64_t quotient = n / COIN;
int64_t remainder = n % COIN;
if (n < 0) {
quotient = -quotient;
remainder = -remainder;
}
std::string str = strprintf("%d.%08d", quotient, remainder);
// Right-trim excess zeros before the decimal point:
int nTrim = 0;
for (int i = str.size()-1; (str[i] == '0' && IsDigit(str[i-2])); --i)
++nTrim;
if (nTrim)
str.erase(str.size()-nTrim, nTrim);
if (n < 0)
str.insert((unsigned int)0, 1, '-');
return str;
*/
}
/**
| Parse an amount denoted in full coins.
| E.g. "0.0034" supplied on the command
| line. *
|
*/
pub fn parse_money(money_string: &String) -> Option<Amount> {
todo!();
/*
if (!ValidAsCString(money_string)) {
return std::nullopt;
}
const std::string str = TrimString(money_string);
if (str.empty()) {
return std::nullopt;
}
std::string strWhole;
int64_t nUnits = 0;
const char* p = str.c_str();
for (; *p; p++)
{
if (*p == '.')
{
p++;
int64_t nMult = COIN / 10;
while (IsDigit(*p) && (nMult > 0))
{
nUnits += nMult * (*p++ - '0');
nMult /= 10;
}
break;
}
if (IsSpace(*p))
return std::nullopt;
if (!IsDigit(*p))
return std::nullopt;
strWhole.insert(strWhole.end(), *p);
}
if (*p) {
return std::nullopt;
}
if (strWhole.size() > 10) // guard against 63 bit overflow
return std::nullopt;
if (nUnits < 0 || nUnits > COIN)
return std::nullopt;
int64_t nWhole = LocaleIndependentAtoi<int64_t>(strWhole);
CAmount value = nWhole * COIN + nUnits;
if (!MoneyRange(value)) {
return std::nullopt;
}
return value;
*/
}