Changeset - f7a57ded868c
[Not reviewed]
0 1 0
Brett Smith - 7 years ago 2017-07-06 14:17:08
brettcsmith@brettcsmith.org
historical: Add comments to explain the precision-finding code.
1 file changed with 5 insertions and 0 deletions:
0 comments (0 inline, 0 general)
oxrlib/commands/historical.py
Show inline comments
...
 
@@ -109,10 +109,15 @@ class LedgerFormatter(Formatter):
 
        if denomination is None:
 
            return amt_s
 
        full_rate = self.rate.convert(1, currency, denomination)
 
        # Starting from self.rate_prec, find the least amount of precision to
 
        # make sure the `from` amount converts exactly to the `to` amount.
 
        to_amt = self.currency_decimal(amount * full_rate, denomination)
 
        for prec in itertools.count(self.rate_prec):
 
            rate = self.normalize_rate(full_rate, prec)
 
            got_amt = self.currency_decimal(amount * rate, denomination)
 
            # If got_amt == to_amt, this is enough precision to do the
 
            # conversion exactly, so we're done.
 
            # If rate == full_rate, there's no more precision available, so stop.
 
            if (got_amt == to_amt) or (rate == full_rate):
 
                break
 
        return "{} {}".format(amt_s, self.format_ledger_rate_raw(rate, denomination))
0 comments (0 inline, 0 general)