Skip to content

Commit

Permalink
Add decimal precision to whole numbers to avoid rounding errors in be…
Browse files Browse the repository at this point in the history
…ancount
  • Loading branch information
farktronix committed Sep 14, 2023
1 parent fa9987f commit a6639f2
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions beancount_reds_importers/libreader/csvreader.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,16 @@ def convert_columns(self, rdr):
# fixup currencies
def remove_non_numeric(x):
return re.sub("[^0-9\.-]", "", str(x).strip()) # noqa: W605
def add_decimal(x):
if '.' not in x:
return x+".00"
return x
currencies = getattr(self, 'currency_fields', []) + ['unit_price', 'fees', 'total', 'amount', 'balance']
for i in currencies:
if i in rdr.header():
rdr = rdr.convert(i, remove_non_numeric)
if self.config.get('add_currency_precision', False):
rdr = rdr.convert(i, add_decimal)
rdr = rdr.convert(i, D)

# fixup dates
Expand Down

0 comments on commit a6639f2

Please sign in to comment.