Closed lasuk closed 2 months ago
CashCtrlLedger.precision(currency: str) -> float
.
Precision is the quantity of digits after the comma. Simple method examples of calculation:
1.02 return -> 0.01
1.0002 return -> 0.0001
1.000002 return -> 0.000001
Or: The smallest increment for amounts in a specified currency is the "smallest unit of currency" or "currency subunit." This increment represents the smallest denomination in which a currency can be divided and is typically the value of the smallest coin or note in circulation. Example:
United States Dollar (USD): The smallest unit is the cent, with 100 cents making up one dollar.
Euro (EUR): The smallest unit is the cent, with 100 cents making up one euro.
smallest increment for amounts in the specified currency
and where to look for it?amount
filed and find a value that has the most digits after the comma?CashCtrl
always returns 2 digits after the comma even if more are passedprecision(currency: str) -> float
and precision is the smallest increment for amounts in a specified currency is the "smallest unit of currency" or "currency subunit." Example:
USD -> smallest is CENT -> 0.01
Mauritania -> Khoums -> 0.00005
Madagascar -> Iraimbilanja -> 0.00005
_settings
field that will store dict for currencies and precisions. By default empty. Define set()
and get()
for it to make it possible for user to provide own precisions.precision(currency: str) -> float
will look up for a currency there, if user haven`t stored something there, return default 0.01
Background
CashCtrl stores a transactions'
currencyRate
instead of thebase_currency_amount
, while pyledger and most large accounting systems choose the more flexible approach and store a transactions'base_currency_amount
.When mapping to/from CashCtrl, we compute
base_currency_amount = amount * currencyRate
. We currently round this amount to eight digits after the comma. The eight digits are arbitrarily chosen and hard coded.Task
CashCtrlLedger.precision(currency: str) -> float
to fetch the smallest increment for amounts in the specified currency from CashCtrl.LedgerEngine.round_to_precision
with a vectorized version.LedgerEngine.round_to_precision
instead ofround(..., 8)
to round thebase_currency_amount
. See TODOs in cashctrl_ledger.