-3

I'm developing a cricket app and I'm getting problems when I'm working with overs. We all know that whatever calculation is done in calculator is done with 10.

For example :

If there are total overs : 20, and current over 2.1 And I want to calculate remaining overs.

So the formula would be : (total overs - current overs)

The answer should be 17.5

But I'm getting the answer as 17.9

Same thing occurrs in run rate and required run rate.

What I'm actually doing wrong?? Anyone has some algorithm or formula or any code that can convert convert overs like this.

Thanks.

Pranav Fulkari
  • 187
  • 2
  • 12

7 Answers7

1
float total=total-0.4;
float current;
float remaining=total-current;
Akshay
  • 24
  • 4
0
public class T {
    public static void main(String[] args) {
        int numberOfBalls=34;
        String round = String.valueOf(Math.round(numberOfBalls / 6));
        String mod=String.valueOf(numberOfBalls%6);
        double numberOfOvers=Double.valueOf(round+"."+mod);
        System.out.println(numberOfOvers);
   }
}
0

This shall help you:

 public float GetOversLeft(){


        var tempOversLeft = TotalOvers % 6;
        var totalBallsLeftInANOver = ((TotalOVers - currentBallNumber) % 6) /10;


         return tempOversLeft + totalBallsLeftInANOver;


    }

    public int GetTotalBallsLeftInOver(){

    var tempBallsLeft=  (int) (  ((TotalBallsInMatch - currentBallNumber)%6));
    if(tempBallsLeft== 0){
        tempBallsLeft= 6;
    }

    return tempBallsLeft;




    }
idurvesh
  • 644
  • 1
  • 7
  • 19
0

For getting over from total balls delivered

public function calculation_over()
{
    $balls = 80;
    $balls2 = 80;
    $balls -= $balls % 6;
    $total_overs = $balls / 6;
    $f = $balls2 % 6;
    echo $total_overs_calculated = (float)$total_overs.'.'.$f;
}

if total balls delivered is 80 balls then first we have to make it divisible by 6 then we get 78 from ($balls -= $balls % 6;) then it will we divided by 6 then we get 13 means 13 over then we have to calculate module of 80 balls then this expression is use $f = $balls2 % 6; for module then i got 2 then i concate both values 13 and 2 with a decimal separator = 13.2(overs) ((float)$total_overs.'.'.$f;) you can test it on ex->43,44,94,110

  • if total balls delivered is 80 balls then first we have to make it divisible by 6 then we get 78 from ($balls -= $balls % 6;) then it will we divided by 6 then we get 13 means 13 over then we have to calculate module of 80 balls then this expression is use $f = $balls2 % 6; for module then i got 2 then i concate both values 13 and 2 with a decimal separator = 13.2(overs) ((float)$total_overs.'.'.$f;) you can test it on ex->43,44,94,110 – Sachin Appslure Jul 24 '19 at 08:41
  • in the post not in comment. – NickCoder Jul 24 '19 at 08:49
0

Simple formula to calculate number of balls from overs bowled

=(FLOOR({overs})*6)+MOD({overs},FLOOR({overs}))*10

Example: Overs = 96.2

Result: Balls = 578

Ahsan Horani
  • 239
  • 2
  • 13
0

This is the simple PHP condition for overcoming this problem. The method is Lengthy but working:-

 $ball__= 15;    
 $over=0;

          if($ball__>=6 && $ball__<12){
              $over+=1;
              if($ball__==6){$ball__=0;}
              if($ball__==7){$ball__=1;}
              if($ball__==8){$ball__=2;}
              if($ball__==9){$ball__=3;}
              if($ball__==10){$ball__=4;}
              if($ball__==11){$ball__=5;}
            }
            if($ball__>=12 && $ball__<18){
              $over+=2;
              if($ball__==12){$ball__=0;}
              if($ball__==13){$ball__=1;}
              if($ball__==14){$ball__=2;}
              if($ball__==15){$ball__=3;}
              if($ball__==16){$ball__=4;}
              if($ball__==17){$ball__=5;}
            }
            if($ball__>=18 && $ball__<24){
              $over+=3;
              if($ball__==18){$ball__=0;}
              if($ball__==19){$ball__=1;}
              if($ball__==20){$ball__=2;}
              if($ball__==21){$ball__=3;}
              if($ball__==22){$ball__=4;}
              if($ball__==23){$ball__=5;}
            }
            if($ball__>=24 && $ball__<30){
              $over+=4;
              if($ball__==24){$ball__=0;}
              if($ball__==25){$ball__=1;}
              if($ball__==26){$ball__=2;}
              if($ball__==27){$ball__=3;}
              if($ball__==28){$ball__=4;}
              if($ball__==29){$ball__=5;}
            }
            if($ball__>=30 && $ball__<36){
              $over+=5;
              if($ball__==30){$ball__=0;}
              if($ball__==31){$ball__=1;}
              if($ball__==32){$ball__=2;}
              if($ball__==33){$ball__=3;}
              if($ball__==34){$ball__=4;}
              if($ball__==35){$ball__=5;}
            }
//----and so on up to the number of balls you have to convert into overs. I have done this up to 6 overs(36 balls).

echo ($over.".".$ball__); to show results

`

  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Feb 10 '23 at 13:47
0

Easy solution to convert balls into overs in golang
package main

import "fmt"

func convertToOvers(totalBalls int) (int, int) {
    overs := totalBalls / 6
    remainingBalls := totalBalls % 6
    return overs, remainingBalls
}

func main() {
    var totalBalls int

    fmt.Print("Enter the total number of balls: ")
    fmt.Scanln(&totalBalls)

    overs, remainingBalls := convertToOvers(totalBalls)

    fmt.Printf("Number of overs: %d.%d\n", overs, remainingBalls)
}