Skip to content

Commit

Permalink
impr(numbers util): add roundTo1 function
Browse files Browse the repository at this point in the history
  • Loading branch information
Miodec committed May 5, 2024
1 parent a6a4e09 commit 413a74b
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions frontend/src/ts/utils/numbers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@ export function median(arr: number[]): number {
}
}

/**
* Rounds a number to one decimal places.
* @param num The number to round.
* @returns The input number rounded to one decimal places.
*/
export function roundTo1(num: number): number {
return Math.round((num + Number.EPSILON) * 10) / 10;
}

/**
* Rounds a number to two decimal places.
* @param num The number to round.
Expand Down

0 comments on commit 413a74b

Please sign in to comment.