Added string conversion op for amounts and balances

This commit is contained in:
John Wiegley 2009-11-20 23:23:22 -05:00
parent 92d2310548
commit bd455c9874
2 changed files with 12 additions and 0 deletions

View file

@ -496,6 +496,9 @@ public:
long to_long() const;
bool fits_in_long() const;
operator string() const {
return to_string();
}
string to_string() const;
string to_fullstring() const;
string quantity_string() const;

View file

@ -461,6 +461,15 @@ public:
* Conversion methods. A balance can be converted to an amount, but
* only if contains a single component amount.
*/
operator string() const {
return to_string();
}
string to_string() const {
std::ostringstream buf;
print(buf);
return buf.str();
}
amount_t to_amount() const {
if (is_empty())
throw_(balance_error, _("Cannot convert an empty balance to an amount"));