MCPcopy Create free account
hub / github.com/ElementsProject/elements / FormatMoney

Function FormatMoney

src/util/moneystr.cpp:15–38  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

13#include <optional>
14
15std::string FormatMoney(const CAmount n)
16{
17 // Note: not using straight sprintf here because we do NOT want
18 // localized number formatting.
19 static_assert(COIN > 1);
20 int64_t quotient = n / COIN;
21 int64_t remainder = n % COIN;
22 if (n < 0) {
23 quotient = -quotient;
24 remainder = -remainder;
25 }
26 std::string str = strprintf("%d.%08d", quotient, remainder);
27
28 // Right-trim excess zeros before the decimal point:
29 int nTrim = 0;
30 for (int i = str.size()-1; (str[i] == '0' && IsDigit(str[i-2])); --i)
31 ++nTrim;
32 if (nTrim)
33 str.erase(str.size()-nTrim, nTrim);
34
35 if (n < 0)
36 str.insert((unsigned int)0, 1, '-');
37 return str;
38}
39
40
41std::optional<CAmount> ParseMoney(const std::string& money_string)

Callers 14

PrioritiseTransactionMethod · 0.85
SetupServerArgsFunction · 0.85
FinalizeMethod · 0.85
PaysForRBFFunction · 0.85
KnapsackSolverFunction · 0.85
AddWalletOptionsMethod · 0.85
CheckFeeRateFunction · 0.85
ToStringMethod · 0.85
listunspentFunction · 0.85
BOOST_AUTO_TEST_CASEFunction · 0.85
FUZZ_TARGET_INITFunction · 0.85
sendrawtransactionFunction · 0.85

Calls 4

IsDigitFunction · 0.85
sizeMethod · 0.45
eraseMethod · 0.45
insertMethod · 0.45

Tested by 2

BOOST_AUTO_TEST_CASEFunction · 0.68
FUZZ_TARGET_INITFunction · 0.68