Let's talk about the point in the remainder operation (%) of php.

Source: Internet
Author: User
Php uses the % symbol to take the remainder, that is, the modulo operation, and the meaning of the remainder. please note this. today I see this example in Baidu: http://zhidao.baidu.com/question/41130500.html&

Php take the remainder with % symbol, that is, the modulo operation, take the meaning of the remainder, this thing can be used to pay attention to it, today I see Baidu know this example: http://zhidao.baidu.com/question/41130500.html, I want to study how to obtain the remainder of php!


 

The questioner wondered why the output above was recorded as 44 rather than the expected 45. if you do this:

Echo 945% 100 // 45

The result should be 45, because php performs the remainder operation on the variables by default.

About php floating point number, laruence blog: http://www.laruence.com/2013/03/26/2884.html

Then let's look at the following php code:


 

For a large integer, php will overflow and may return a negative number (this is because php uses an integer to take the remainder by default, so you need to convert it to the float type (as shown above )) you can do this:


function Kmod($bn, $sn){return intval(fmod(floatval($bn), $sn));}

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.