Skip to content

Commit

Permalink
Fix parseNumber in case of 3 numbers after decimal dot
Browse files Browse the repository at this point in the history
  • Loading branch information
Minstel committed Dec 2, 2018
1 parent db4ab79 commit d2a6ae1
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 d2a6ae1

Please sign in to comment.