数字四舍五入的问题 $n = 1.2;//$n = 1.6;$t = explode('.', "$n");$n = $t[1]{0} < 5 ? $t[0] + .5 : round($n);echo $n; 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 function test($val){ $x=explode('.',sprintf("%.1f", $val)); $a=$x[0]; $d=$x[1]; if($d>0 && $d<5){ $r=$a+0.5; }else{ $r=round($val); } return $r;}echo test(1);//1echo test(1.11);//1.5echo test(1.5);//2echo test(1.6);//2 function fn($num) { return ceil($num * 2) / 2;} 需求要说清楚for($i=1; $i<2; $i+=0.1) printf("%.1f : %s\n", $i, ceil($i * 2) / 2);1.0 : 11.1 : 1.51.2 : 1.51.3 : 1.51.4 : 1.51.5 : 21.6 : 21.7 : 21.8 : 21.9 : 2 $arr = array(1.0,1.1,1.2,1.3,1.4,1.5,1.6,1.7,1.8,1.9,2.0,2.1);foreach($arr as $v){ echo $v.' -> '.fn($v).'<br>';}function fn($num){ return ($ret=round($num, 0))>=$num? $ret : $ret+0.5;}1 -> 11.1 -> 1.51.2 -> 1.51.3 -> 1.51.4 -> 1.51.5 -> 21.6 -> 21.7 -> 21.8 -> 21.9 -> 22 -> 22.1 -> 2.5 Zend Guard Loader 只有VC9版本吗,哪位兄弟帮忙找找VC6版本的 简单的css问题 站内公告如何设计? 一个关于linux系统的问题 网站出现这个错误怎么办?Can't create/write to file 请教各位一个问题好吗 请问如何将连接后面带的PHPSESSID去掉。linux9.0 + php4.2 + apache2.0 ,在线等! ★十万火急,大侠们请帮忙了!!!★ php参数问题 调出来的值是从1到9中任意几个,怎么实现输出的时候1代表a 2代表b..以此类推 点击文章标题跳转到html界面问题 我不要它验证登陆 就可以看这个页面
function test($val){
$x=explode('.',sprintf("%.1f", $val));
$a=$x[0];
$d=$x[1];
if($d>0 && $d<5){
$r=$a+0.5;
}else{
$r=round($val);
}
return $r;
}echo test(1);//1
echo test(1.11);//1.5
echo test(1.5);//2
echo test(1.6);//2
return ceil($num * 2) / 2;
}
printf("%.1f : %s\n", $i, ceil($i * 2) / 2);
1.0 : 1
1.1 : 1.5
1.2 : 1.5
1.3 : 1.5
1.4 : 1.5
1.5 : 2
1.6 : 2
1.7 : 2
1.8 : 2
1.9 : 2
$arr = array(1.0,1.1,1.2,1.3,1.4,1.5,1.6,1.7,1.8,1.9,2.0,2.1);foreach($arr as $v){
echo $v.' -> '.fn($v).'<br>';
}function fn($num){
return ($ret=round($num, 0))>=$num? $ret : $ret+0.5;
}
1 -> 1
1.1 -> 1.5
1.2 -> 1.5
1.3 -> 1.5
1.4 -> 1.5
1.5 -> 2
1.6 -> 2
1.7 -> 2
1.8 -> 2
1.9 -> 2
2 -> 2
2.1 -> 2.5