summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--amount.cc43
-rw-r--r--balance.cc18
-rw-r--r--balance.h9
3 files changed, 27 insertions, 43 deletions
diff --git a/amount.cc b/amount.cc
index 2e8fc8fb..00610c05 100644
--- a/amount.cc
+++ b/amount.cc
@@ -503,32 +503,37 @@ std::ostream& operator<<(std::ostream& out, const amount_t& amt)
out << quotient;
}
else {
- bool printed = false;
+ strings_list strs;
+ char buf[4];
mpz_t temp;
mpz_init(temp);
- // jww (2003-09-29): use a smarter starting value for `powers'
- for (int powers = 15; powers >= 0; powers -= 3) {
- mpz_ui_pow_ui(divisor, 10, powers);
- mpz_tdiv_q(temp, quotient, divisor);
-
- if (mpz_sgn(temp) == 0)
- continue;
+ for (int powers = 0; true; powers += 3) {
+ if (powers > 0) {
+ mpz_ui_pow_ui(divisor, 10, powers);
+ mpz_tdiv_q(temp, quotient, divisor);
+ if (mpz_sgn(temp) == 0)
+ break;
+ mpz_tdiv_r_ui(temp, temp, 1000);
+ } else {
+ mpz_tdiv_r_ui(temp, quotient, 1000);
+ }
+ mpz_get_str(buf, 10, temp);
+ strs.push_back(buf);
+ }
- mpz_ui_pow_ui(divisor, 10, 3);
- mpz_tdiv_r(temp, temp, divisor);
+ bool printed = false;
+ for (strings_list::iterator i = strs.begin(); i != strs.end(); i++) {
if (printed) {
+ out << (amt.commodity->flags & COMMODITY_STYLE_EUROPEAN ? '.' : ',');
out.width(3);
out.fill('0');
}
- out << temp;
+ out << *i;
- if (powers > 0) {
- out << ((amt.commodity->flags & COMMODITY_STYLE_EUROPEAN) ? '.' : ',');
- printed = true;
- }
+ printed = true;
}
mpz_clear(temp);
@@ -622,10 +627,10 @@ void amount_t::parse(std::istream& in)
// [-]NUM[ ]SYM [@ AMOUNT]
// SYM[ ][-]NUM [@ AMOUNT]
- std::string symbol;
- std::string quant;
- unsigned int flags = COMMODITY_STYLE_DEFAULTS;;
- unsigned int precision = MAX_PRECISION;
+ std::string symbol;
+ std::string quant;
+ unsigned int flags = COMMODITY_STYLE_DEFAULTS;;
+ unsigned int precision = MAX_PRECISION;
INIT();
diff --git a/balance.cc b/balance.cc
index eeef3d49..7ecdab4e 100644
--- a/balance.cc
+++ b/balance.cc
@@ -18,20 +18,6 @@ amount_t balance_t::amount(const commodity_t * commodity) const
return amount_t();
}
-#if 0
-balance_t balance_t::round() const
-{
- balance_t temp;
-
- for (amounts_map::const_iterator i = amounts.begin();
- i != amounts.end();
- i++)
- temp += (*i).second.round();
-
- return temp;
-}
-#endif
-
balance_t balance_t::value(const std::time_t moment) const
{
balance_t temp;
@@ -41,11 +27,7 @@ balance_t balance_t::value(const std::time_t moment) const
i++)
temp += (*i).second.value(moment);
-#if 1
return temp;
-#else
- return temp.round();
-#endif
}
void balance_t::write(std::ostream& out,
diff --git a/balance.h b/balance.h
index 888dd13e..5390a15e 100644
--- a/balance.h
+++ b/balance.h
@@ -333,14 +333,11 @@ class balance_t
}
amount_t amount(const commodity_t * commodity = NULL) const;
-#if 0
- balance_t round() const;
-#endif
balance_t value(const std::time_t moment) const;
- void write(std::ostream& out,
- const int first_width,
- const int latter_width = -1) const;
+ void write(std::ostream& out,
+ const int first_width,
+ const int latter_width = -1) const;
};
inline balance_t abs(const balance_t& bal) {