A question about floating point modulo

Source: Internet
Author: User
A question about floating point modulo operation is a routine in the book & lt ;? Php $ a5; $ b3; echo & nbsp; $ a $ B % $ B ;? & Gt; the result of the above case Modulo is 1. The following is my personal understanding, but I am not sure. please give me your answers. $ A $ B Get a floating-point number as the divisor and % B as the divisor. when the divisor is floating-point and smaller than the divisor, the modulo is less than 1, whether to automatically add the first digit after the decimal point to 1 without rounding it out: a question about floating point modulo
A routine in the book
 $ A = 5;
$ B = 3;
Echo $ a/$ B % $ B;
?>


The result of the above case Modulo is 1.

The following is my personal understanding, but I am not sure. please give me your answers.
$ A/$ B Get a floating point number as the divisor and % B as the divisor to perform the modulo operation. when the divisor is floating and less than the divisor, the number of modulo operations is less than 1, does it mean to automatically add the first digit after the decimal point to 1 without rounding it down?

Share: More


------ Solution --------------------
Decimal place, integer modulo
Echo $ a/$ B; // 1.6666666666667.
Echo 1.6666666666667% $ B; // 1

------ Solution --------------------
The division operator always returns a floating point number. Only in the following cases: both operands are integers (or integers converted into strings) and can be fully divided. in this case, an integer is returned.

The operands of the modulo operator are converted to integers (excluding decimal digits) before the operation ).

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.