-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(frontend): correct getRandomNumber value rounding
- Loading branch information
1 parent
9bff429
commit df9ae1e
Showing
7 changed files
with
33 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,17 @@ | ||
export const getRandomNumber = (min: number, max: number, precision?: number): number => { | ||
const floating = typeof precision === 'number' | ||
const MIN_FIX = 0 | ||
const MAX_FIX = 100 | ||
|
||
export const getRandomNumber = (min: number, max: number, fix: number = 0): number => { | ||
let randomValue = Math.random() * (max - min) + min | ||
|
||
if (floating) { | ||
randomValue = parseFloat(randomValue.toPrecision(precision)) | ||
if (fix < MIN_FIX) { | ||
fix = MIN_FIX | ||
} | ||
if (fix > MAX_FIX) { | ||
fix = MAX_FIX | ||
} | ||
|
||
randomValue = parseFloat(randomValue.toFixed(fix)) | ||
|
||
return randomValue | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters