PHP four six in (banker rounding) how to achieve? Is there a way out?

Source: Internet
Author: User
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.

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.