Skip to content

Commit 9abaf62

Browse files
committed
added overflow check
1 parent 41720fc commit 9abaf62

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/Tetrifact.Core/Percent.cs

+8
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ public class Percent
1111
/// <returns></returns>
1212
public static int Calc(decimal first, decimal second)
1313
{
14+
// overflow check
15+
if (second == 0)
16+
return 0;
17+
1418
decimal p = first / second;
1519
return (int)System.Math.Round((decimal)(p * 100), 0);
1620
}
@@ -23,6 +27,10 @@ public static int Calc(decimal first, decimal second)
2327
/// <returns></returns>
2428
public static int Calc(double first, double second)
2529
{
30+
// overflow check
31+
if (second == 0)
32+
return 0;
33+
2634
double p = first / second;
2735
return (int)System.Math.Round((double)(p * 100), 0);
2836
}

0 commit comments

Comments
 (0)