feat: add utilization to pool information
[poolifier.git] / src / utils.ts
index 87c4888db0770d15bc624371eccb716809938934..6d11f88cf6d964bfc9f36fe79b5c3eda3810d35b 100644 (file)
@@ -51,7 +51,7 @@ export const availableParallelism = (): number => {
 }
 
 /**
- * Compute the median of the given data set.
+ * Computes the median of the given data set.
  *
  * @param dataSet - Data set.
  * @returns The median of the given data set.
@@ -71,6 +71,18 @@ export const median = (dataSet: number[]): number => {
   )
 }
 
+/**
+ * Rounds the given number to the given scale.
+ *
+ * @param num - The number to round.
+ * @param scale - The scale to round to.
+ * @returns The rounded number.
+ */
+export const round = (num: number, scale = 2): number => {
+  const rounder = Math.pow(10, scale)
+  return Math.round(num * rounder * (1 + Number.EPSILON)) / rounder
+}
+
 /**
  * Is the given object a plain object?
  *