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