Ask PHP four to six in (banker rounding) how to achieve? Thank you, everyone.
Reply content:
Ask PHP four to six in (banker rounding) how to achieve? Thank you, everyone.
The Rounding method is round (), which is documented here:
http://php.net/manual/zh/function.round.php
Such as:
php -r "echo round(1/8,2);"
Will output:
0.13
However, if your float is not coming from somewhere else (for example, $_get incoming, or taken from a database), but you calculate it yourself in two numbers, remember, do not use the PHP built-in +-*/operator, use Bcmath, execute the following code you know why:
php -r "echo 19.45-19.35;"
I also thought you were a clerical error, answered the rounding, the banker rounding method is also ROUND (), the third parameter with Php_round_half_even and php_round_half_odd can be, as
php -r "echo round(1/8,2,PHP_ROUND_HALF_ODD);"
You ask is five six into the bar, four six in the words, five how to do?
round($number, PHP_ROUND_HALF_DOWN);
UPDATE
Check it out, there really are bankers rounding this four-shed six into, five-look at the odd-even approach
Php_round_half_odd or Php_round_half_even, maybe you want it.
It's in the manual.