Browse Source

Fix getPercent when first value was 0

Ricardo Maltez 2 years ago
parent
commit
5106d6256a
1 changed files with 1 additions and 1 deletions
  1. 1 1
      index.ts

+ 1 - 1
index.ts

@@ -6,7 +6,7 @@ export const sum = (a: number[]) =>
   a.reduce((s: number, i: number) => s + i, 0);
 
 export const getPercent = (value1: number, value2: number): number => {
-  if (value1 === 0) return value2 > 0 ? 100 : 0;
+  if (value1 === 0) return value2 > 0 ? Infinity : 0;
   return Number(((value2 * 100) / value1 - 100).toFixed(2));
 };