如何系统知道一个板球有6球(计算)在Android

x33g5p2x  于 2023-05-21  发布在  Android
关注(0)|答案(7)|浏览(115)

我正在开发一个板球应用程序,当我与over一起工作时,我遇到了问题。我们都知道,在计算器中进行的任何计算都是用10来完成的。
例如:
如果存在总超额:20,电流超过2.1,我想计算剩余的电流。
所以公式是:(总结余-本期结余)
答案应该是17.5
但我得到的答案是17.9
同样的事情发生在运行率和所需的运行率。
我到底做错了什么?任何人都有一些算法或公式或任何代码,可以转换转换这样的转换。
谢谢

lf5gs5x2

lf5gs5x21#

float total=total-0.4;
float current;
float remaining=total-current;
luaexgnf

luaexgnf2#

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);
   }
}
eivnm1vs

eivnm1vs3#

这将帮助您:

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;



    }
ojsjcaue

ojsjcaue4#

为了从总球交付

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;
}

如果总球交付是80球然后首先我们必须使它被6整除然后我们得到78从($balls -= $balls % 6;)然后我们除以6,然后我们得到13,意味着13,然后我们必须计算80个球的模,然后这个表达式是使用$f =$balls2% 6;对于模块,然后我得到了2,然后我将值13和2与十进制分隔符= 13.2(overs)((float)$total_overs.'.'.$f;)可以在ex-> 43,44,94,110上测试

jckbn6z7

jckbn6z75#

简单的公式来计算球的数量从过投球

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

示例:超出= 96.2
结果:球= 578

9jyewag0

9jyewag06#

这是克服这个问题的简单PHP条件。该方法很长,但工作:

$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

iih3973s

iih3973s7#

  • 简单的解决方案,将球转换成在golang*

主程序包

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)
}

相关问题