Procházet zdrojové kódy

Merge pull request #17 from erikmd/fix-rounding

Ensure percentA() and percentB() don't truncate the floating-point division
lama0206 před 10 roky
rodič
revize
7e0efe941a
1 změnil soubory, kde provedl 2 přidání a 2 odebrání
  1. 2 2
      jplag/src/main/java/jplag/AllMatches.java

+ 2 - 2
jplag/src/main/java/jplag/AllMatches.java

@@ -106,13 +106,13 @@ public class AllMatches extends Matches implements Comparator<AllMatches> {
   	int divisor;
   	if(bcmatchesA != null) divisor = subA.size()-subA.files.length-bcmatchesA.tokensMatched();
     else divisor = subA.size()-subA.files.length;
-    return (divisor == 0 ? 0 : (tokensMatched()*100 / divisor));
+    return (divisor == 0 ? 0f : (tokensMatched()*100 / (float) divisor));
   }
   public final float percentB() {
     int divisor;
 	if(bcmatchesB != null) divisor = subB.size()-subB.files.length-bcmatchesB.tokensMatched();
 	else divisor = subB.size()-subB.files.length;
-    return (divisor == 0 ? 0 : (tokensMatched()*100 / divisor));
+    return (divisor == 0 ? 0f : (tokensMatched()*100 / (float) divisor));
   }
 
   public final float roundedPercentMaxAB() {