historical: Add comments to explain the precision-finding code.
This commit is contained in:
parent
d0f5f1547c
commit
f7a57ded86
1 changed files with 5 additions and 0 deletions
|
@ -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))
|
||||
|
|
Loading…
Reference in a new issue