php round 2e decimal to 0 or 5

后端 未结 2 1357
走了就别回头了
走了就别回头了 2020-12-22 13:15

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         


        
2条回答
  •  死守一世寂寞
    2020-12-22 13:50

    You can double the value so you can round to 1 decimal, then simple divide it by 2 again

    $t = round(($t*2), 1) / 2;
    

提交回复
热议问题