Skip to content

Commit

Permalink
refactor(parser): improve decimal parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
fkleuver committed Apr 28, 2018
1 parent fdbb497 commit bb185e3
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit bb185e3

Please sign in to comment.