Rounding Mechanism to nearest 0.05

后端 未结 10 1983
离开以前
离开以前 2021-01-05 00:15

I would like to solve rounding mechanism by using php4,5.2 and below (not 5.3) Currently I am doing 0.05 rounding, something like this page:

http://www.bnm.gov.my/in

10条回答
  •  失恋的感觉
    2021-01-05 00:25

    function round5Sen ($value) { 
    
        return number_format(round($value*20,0)/20,2,'.','');
    } 
    
    echo round5Sen(155.13);
    echo "\n";
    echo round5Sen(155.12);
    echo "\n";
    echo round5Sen(155.0);
    echo "\n";
    echo round5Sen(155.18);
    echo "\n";
    

提交回复
热议问题