PHP小数点

Ser*_*gio 7 php rounding

是否可以用PHP将小数点数舍入到最接近的.5,如下所示:

number | round
----------------
 1.29  |  1.50
 2.03  |  2.00
 1.43  |  1.50
 1.13  |  1.00
11.38  | 11.50
Run Code Online (Sandbox Code Playgroud)

我尝试过:

$rnd= round($number,2);
Run Code Online (Sandbox Code Playgroud)

但我得到的小数就像上面"数字"栏中的小数字一样.

Art*_*cto 17

function round_to_nearest_half($number) {
    return round($number * 2) / 2;
}
Run Code Online (Sandbox Code Playgroud)