如何使用php来获取这种格式?
我想得到这样的结果
inpput====> output
.....
3.0 =======> 3.0
3.1 =======> 3.0
3.2 =======> 3.0
3.3 =======> 3.0
3.4 =======> 3.0
3.5 =======> 4.0
3.6 =======> 4.0
3.7 =======> 4.0
3.8 =======> 4.0
3.9 =======> 4.0...................................................................
所以,我使用这个代码
$x = floor($input);但我得到这个结果
inpput====> output
.....
3.0 =======> 3.0
3.1 =======> 3.0
3.2 =======> 3.0
3.3 =======> 3.0
3.4 =======> 3.0
3.5 =======> 3.0
3.6 =======> 3.0
3.7 =======> 3.0
3.8 =======> 3.0
3.9 =======> 3.0...................................................................
然后我使用这个代码
$x = ceil($input);但我得到这个结果
inpput====> output
.....
3.0 =======> 3.0
3.1 =======> 4.0
3.2 =======> 4.0
3.3 =======> 4.0
3.4 =======> 4.0
3.5 =======> 4.0
3.6 =======> 4.0
3.7 =======> 4.0
3.8 =======> 4.0
3.9 =======> 4.0我该怎么做才能得到这个结果?
inpput====> output
.....
3.0 =======> 3.0
3.1 =======> 3.0
3.2 =======> 3.0
3.3 =======> 3.0
3.4 =======> 3.0
3.5 =======> 4.0
3.6 =======> 4.0
3.7 =======> 4.0
3.8 =======> 4.0
3.9 =======> 4.0发布于 2017-11-21 03:04:00
使用圆形函数。前任,
$x = round ($input);参考文献:http://php.net/manual/en/function.round.php
发布于 2017-11-21 03:05:32
使用第()轮函数,您就可以访问舍入模式。
<?php
foreach(range(3, 4, 0.1) as $i) {
echo $i.' =======> '.number_format(round($i, 0, PHP_ROUND_HALF_UP), 1).PHP_EOL;
}
/*
3 =======> 3.0
3.1 =======> 3.0
3.2 =======> 3.0
3.3 =======> 3.0
3.4 =======> 3.0
3.5 =======> 4.0
3.6 =======> 4.0
3.7 =======> 4.0
3.8 =======> 4.0
3.9 =======> 4.0
4 =======> 4.0
*/https://stackoverflow.com/questions/47404463
复制相似问题