在PHP中限制剩余部分

I have a code in which calculates the Effective interest rate. when I echo it I get 5.1161897881733 which I want to limit the remainder and output it like 5.11, is there any functions use to limit the remainder in php?

A billion ways to do this. The task for you here is to pick one.

Method 1 - round()

This will just round your number. The exact rules can be found in the PHP.net documentation.

round($someNumber, 2);

Method 2 - floor()

Floor will round the number down

floor($someNumber, 2);

Method 3 - ceil()

Opposite to floor() this will round your number upwards.

ceil($someNumber, 2);

Method 4 - number_format()

This will format any number. number_format() has a gazillion possible inputs in which you can choose decimal characters etc.

// Will round your number to 2 decimals with a . as decimal character
number_format($someNumber, 2, ",", ".");

Feel free to edit and add more options :)

round($result, 0)

The 0 represents the decimal places.

http://php.net/manual/en/function.round.php