我试着把一个像"2.4“这样的字符串从2.9递增到2.10,2.11等等。请协助,已经搜索了两天!这是我最后一次孤注一掷。
$update =$note;// (float) $note;
for($x=1;$x<sizeof($index);$x++){
if(preg_match("/\.9/s", $update)){
$u = explode(".", $update);
$update = number_format($u[0]+".10", 2);
}else{
$u = explode(".", $update);
if(strlen($u[1])==2){
$add + $u[2]+="1";
$update = "{$u[0]}"."."."{$u[1]}{$add}";
}else{
$update += ".1";
}
}
echo $update."\r";
}
}发布于 2015-10-02 02:06:53
试试这个:
$string = "2.42";
$nums = explode(".", $string);
$whole = $nums[0];
$decimals = intval($nums[1]);
$add_times = 10;
for ($i = 0; $i < $add_times; $i++) {
$decimals += 1;
$final_num = floatval($whole . "." . $decimals);
var_dump($final_num);
}https://stackoverflow.com/questions/32893786
复制相似问题