Added a number asset to limit to a specific number of decimal cases if needed

This commit is contained in:
Joao Ramos
2023-12-14 17:20:36 +00:00
parent d57223bd01
commit 45cf2dc279
3 changed files with 19 additions and 5 deletions

13
src/utils/number.ts Normal file
View File

@@ -0,0 +1,13 @@
export function isDecimal(num: number) {
return num % 1 !== 0;
}
export function toFixedNumber(num: number, decimals: number = 2) {
// Rounds to 2 decimal places
if(isDecimal(num)) {
const multiplier = Math.pow(10, decimals);
return Math.round(num * multiplier) / multiplier;
}
return num;
}