开发者

PHP round decimals

Is it possible to round a decimals to the nearest .5 with PH开发者_StackOverflowP like this:

number | round
----------------
 1.29  |  1.50
 2.03  |  2.00
 1.43  |  1.50
 1.13  |  1.00
11.38  | 11.50

I tried with:

$rnd= round($number,2);

but I get decimals like the one in the column "number" above.


function round_to_nearest_half($number) {
    return round($number * 2) / 2;
}


You don't want write any function for this php round function already have the option, in mode is a third argument of round function. for more reference PHP Round Function

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜