PHP将2e小数舍入为0或5 [英] php round 2e decimal to 0 or 5
本文介绍了PHP将2e小数舍入为0或5的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将$ t 2e小数舍入为0或5.
i want to round $t 2e decimal to 0 or 5.
if $t= 1.31; //round to 1.30
if $t= 1.32 //round to 1.30
if $t= 1.33; //round to 1.35
if $t= 1.34; //round to 1.35
if $t= 1.36; //round to 1.35
if $t= 1.37 //round to 1.35
if $t= 1.38; //round to 1.40
if $t= 1.39; //round to 1.40
推荐答案
尝试这一步,检查演示
0.05 *舍入($ t * 20)
0.05 * round($t * 20)
<?php
$ts= [1.31, 1.32, 1.33, 1.34, 1.35, 1.36, 1.37, 1.38, 1.39, 1.40];
array_walk($ts, function($t){echo number_format($t, 2)."\t".number_format(0.05*round($t*20), 2)."\n";});
输出
1.31 1.30
1.32 1.30
1.33 1.35
1.34 1.35
1.35 1.35
1.36 1.35
1.37 1.35
1.38 1.40
1.39 1.40
1.40 1.40
这篇关于PHP将2e小数舍入为0或5的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文