Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix parseNumber in case of 3 numbers after decimal dot #127

Merged
merged 2 commits into from
Dec 6, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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