Skip to content

Commit 2ecc229

Browse files
committed
Merge pull request #3 from pinaraf/decimal
Float, for money related data, is a wrong idea
2 parents e28b8e6 + 9ab172a commit 2ecc229

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

cfonb/parser/common.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# python import
22
from datetime import datetime
3+
import decimal
34
import math
45
import re
56

@@ -440,9 +441,9 @@ def parse_amount(amount_str, nb_of_dec):
440441
debit_trans = {'J': '1', 'K': '2', 'L': '3', 'M': '4', 'N': '5',
441442
'O': '6', 'P': '7', 'Q': '8', 'R': '9', '}': '0'}
442443
if amount_str[-1] in debit_trans:
443-
amount_num = -float(amount_str.replace(amount_str[-1], debit_trans[amount_str[-1]]))
444+
amount_num = decimal.Decimal('-' + amount_str.replace(amount_str[-1], debit_trans[amount_str[-1]]))
444445
elif amount_str[-1] in credit_trans:
445-
amount_num = float(amount_str.replace(amount_str[-1], credit_trans[amount_str[-1]]))
446+
amount_num = decimal.Decimal(amount_str.replace(amount_str[-1], credit_trans[amount_str[-1]]))
446447
else:
447448
raise Exception('Bad amount string')
448449
return amount_num

0 commit comments

Comments
 (0)