Skip to content

Commit

Permalink
Merge pull request #127 from legalthings/fix_for_parseNumber
Browse files Browse the repository at this point in the history
Fix parseNumber in case of 3 numbers after decimal dot
  • Loading branch information
svenstm committed Dec 6, 2018
2 parents 1c94664 + 5d7ce7a commit b05cee4
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions js/lib/parse-number.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ if (typeof module !== 'undefined' && typeof module.exports !== 'undefined') {
module.exports = parseNumber;
}

var numberRegexp = new RegExp('^(?:((?:\\d{1,3}(?:\\.\\d{3})+|\\d+)(?:,\\d{1,})?)|((?:\\d{1,3}(?:,\\d{3})+|\\d+)(?:\\.\\d{1,})?))$');
var numberRegexp = new RegExp('^(?:((?:\\d{1,3}(?:\\.\\d{3})+|\\d+)(,\\d{1,})?)|((?:\\d{1,3}(?:,\\d{3})+|\\d+)(\\.\\d{1,})?))$');
var dotRegexp = /\./g;
var commaRegexp = /,/g;

Expand All @@ -23,7 +23,9 @@ function parseNumber(number) {
var match = number.match(numberRegexp);
if (!match) return null;

var isDecimalComma = typeof match[1] !== 'undefined';
var isDecimalComma =
typeof match[2] !== 'undefined' ||
(typeof match[3] !== 'undefined' && typeof match[4] === 'undefined');

number = isDecimalComma ?
number.replace(dotRegexp, '').replace(',', '.') :
Expand Down

0 comments on commit b05cee4

Please sign in to comment.