From bb185e38493c0ea073fa1559f47a1565f824777b Mon Sep 17 00:00:00 2001 From: Fred Kleuver Date: Sat, 28 Apr 2018 23:42:34 +0200 Subject: [PATCH] refactor(parser): improve decimal parsing --- src/parser.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/parser.js b/src/parser.js index b01f79a8..76867c28 100644 --- a/src/parser.js +++ b/src/parser.js @@ -530,16 +530,22 @@ export class ParserImplementation { this.nextChar(); } - const nonDigitStart = this.index; if (this.currentChar === $PERIOD) { - isFloat = true; this.nextChar(); + let decimalValue = 0; + let decimalPlaces = 0; + while (isDigit(this.currentChar)) { + decimalValue = decimalValue * 10 + (this.currentChar - $0); + decimalPlaces++; this.nextChar(); } + + value += (decimalValue / Math.pow(10, decimalPlaces)); } + const nonDigitStart = this.index; if (this.currentChar === $e || this.currentChar === $E) { isFloat = true; const exponentStart = this.index; // for error reporting in case the exponent is invalid