Using PHP to retrieve the remainder of a large number (floating point number)

Source: Internet
Author: User
This article mainly introduces the method for retrieving the remainder of a large number (floating point number) in PHP, and analyzes the related operation skills related to php mathematical operations in the form of examples, for more information about how to use PHP to retrieve the remainder of a large number (floating point number), I analyzed the php mathematical operation skills in the form of examples. For more information, see

This example describes how to implement the remainder of a large number (floating point number) in PHP. We will share this with you for your reference. The details are as follows:

Generally, the first thing we think of when performing the remainder operation is to use the percent sign %. However, when the divisor is a large value beyond the int range, the remainder is inaccurate.

The remainder function of the php large number (floating point number) is as follows:


/*** Php return the remainder of a large number ** @ param int or float $ bn division * @ param int $ sn division * @ return int remainder * // Large number (floating point number) remainder method function Kmod ($ bn, $ sn) {return intval (fmod (floatval ($ bn), $ sn ));}


Test code:


// Function Kmod ($ bn, $ sn) {return intval (fmod (floatval ($ bn), $ sn ));} // function mod ($ bn, $ sn) {return $ bn % $ sn;} // The largest int integer $ bn = PHP_INT_MAX; $ sn = 11; var_dump ($ bn); var_dump (Kmod ($ bn, $ sn); var_dump (mod ($ bn, $ sn )); // add 1 $ bn = PHP_INT_MAX + 1 to the largest int integer; var_dump ($ bn); var_dump (Kmod ($ bn, $ sn )); var_dump (mod ($ bn, $ sn ));


Execution result:


int 2147483647int 1int 1float 2147483648int 2int -2

For more articles about how to implement the remainder of a large number (floating point number) in PHP, refer to the PHP Chinese network!

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.