Skip to content

Commit

Permalink
fix: stack overflow issue for precision > 2
Browse files Browse the repository at this point in the history
  • Loading branch information
joelsantosjunior committed Sep 15, 2021
1 parent 0a1ff2b commit 364644d
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/input.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,13 @@ export class InputService {
// Ensure max is at least as large as min.
max = (this.isNullOrUndefined(max) || this.isNullOrUndefined(min)) ? max : Math.max(max, min);

// Ensure precision number works well with more than 2 digits
// 23 / 100... 233 / 1000 and so on
const divideBy = Number('1'.padEnd(precision + 1, '0'));

// Restrict to the min and max values.
let newValue = integerValue + (decimalValue / 100);
let newValue = integerValue + (decimalValue / divideBy);

newValue = isNegative ? -newValue : newValue;
if (!this.isNullOrUndefined(max) && newValue > max) {
return this.applyMask(true, max + '');
Expand Down

0 comments on commit 364644d

Please sign in to comment.