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