Skip to content

Commit c6b7708

Browse files
committed
Add normalize_number method
1 parent 4d1ebc7 commit c6b7708

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

lib/monetize/parser.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,7 @@ def parse
5151

5252
negative, num = extract_sign(num)
5353

54-
num.chop! if num =~ /[\.|,]$/
55-
56-
major, minor = extract_major_minor(num)
57-
58-
amount = to_big_decimal([major, minor].join(DEFAULT_DECIMAL_MARK))
54+
amount = to_big_decimal(normalize_number(num))
5955
amount = apply_multiplier(multiplier_exp, amount)
6056
amount = apply_sign(negative, amount)
6157

@@ -64,6 +60,10 @@ def parse
6460

6561
private
6662

63+
def normalize_number(num)
64+
extract_major_minor(num.sub(/[\.|,]$/, "")).join(DEFAULT_DECIMAL_MARK)
65+
end
66+
6767
def to_big_decimal(value)
6868
BigDecimal(value)
6969
rescue ::ArgumentError => err

0 commit comments

Comments
 (0)