Skip to content

Commit 9ab172a

Browse files
committed
Float, for money related data ? Bad idea
1 parent 3bffd9a commit 9ab172a

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

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

0 commit comments

Comments
 (0)