gpt4 book ai didi

PHP 数学转换金额

转载 作者:可可西里 更新时间:2023-10-31 23:20:43 24 4
gpt4 key购买 nike

我正在尝试转换板球比赛,即 6 显示 0.612 显示 1.6。除了返回完整数字的最后一部分外,我一切正常。

我的代码:

foreach($numberofballs as $x){
$first = floor($x / 6);
$last = $x - ($first * 6);
echo $first.'.'.$last;
}

让我们分配一个数组进行测试假设下面的数组需要为这个循环转换

$numberofballs = array(1,2,3,4,5,6);

foreach($numberofballs as $x){
$first = floor($x / 6);
$last = $x - ($first * 6);
echo $first.'.'.$last;
}

/* notes
for 1 it does it right = 0.1
for 2 it does it right = 0.2
for 3 it does it right = 0.3
for 4 it does it right = 0.4
for 5 it does it right = 0.5
how its supposed to work for 6:
for 6 I do not want to get = 1 I would like to get 0.6 and no there is never 0.7
/ end notes */

我并不是说上面的代码是错误的,我只是希望得到正确的最终值。

最佳答案

尝试这样的事情:

foreach( $numberofballs as $x){


$first = floor($x / 6);
$last = $x - ($first * 6);
if($last==0 && $first>0) {$last=6; $first-=1;}
echo $first.'.'.$last;
}

关于PHP 数学转换金额,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21810601/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com