Skip to content

Commit

Permalink
fix(utils): fix unexpected NaN when decimal equal 0
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaodong2008 committed Apr 17, 2024
1 parent 94cd7b8 commit f5614d3
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/utils/methods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,13 @@ function rand(min: number, max: number, decimal: number = 0): number {
}
}

[min, max] = [min * (decimal * 10), max * (decimal * 10)];
const prefix = (decimal * 10) || 1;
[min, max] = [min * prefix, max * prefix];
let num =
(Math.floor(Math.pow(10, 14) * Math.random() * Math.random()) %
(max - min + 1)) +
min;
return num / (decimal * 10);
return num / prefix;
}

export { copy, rand };
Expand Down

0 comments on commit f5614d3

Please sign in to comment.