How does php implement four homes and six homes (banner rounding? Is there a ready-made method?

Source: Internet
Author: User
Ask how php is implemented in four homes and six homes (banner rounding? Thank you ~ Ask how php is implemented in four homes and six homes (banner rounding? Thank you ~

Reply content:

Ask how php is implemented in four homes and six homes (banner rounding? Thank you ~

The rounding method is round (). The document is here:
Http://php.net/manual/zh/function.round.php
For example:

Php-r "echo round (1/8, 2 );"

Output:

0.13

However, if your floating point number is not transmitted from other places (for example, $ _ GET or from the database), but calculated by yourself using two numbers, please remember, do not use the +-*/operator built in PHP. Use bcmath and run the following code to find out the cause:

Php-r "echo 19.45-19.35 ;"

I thought you were wrong. I answered the question, and the banker's rounding method is also round (). The third parameter is used.PHP_ROUND_HALF_EVENAndPHP_ROUND_HALF_ODDYes, for example

Php-r "echo round (1/8, 2, PHP_ROUND_HALF_ODD );"

What do you mean by five homes and six homes?

Round ($ number, PHP_ROUND_HALF_DOWN );
UPDATE

I checked it out. Some bankers really round off this four-house-six-in-one, five-view parity practice.
PHP_ROUND_HALF_ODD or PHP_ROUND_HALF_EVEN may be what you want
The manual contains

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.