Related Solutions for returning negative numbers from the remainder of a PHP integer. Although the PHP language is powerful, it does not mean that it has no disadvantages. During code writing, you may encounter some headaches. Next we will introduce you to the PHP language for integer fetch, although powerful, but it does not mean that it has no disadvantages. in the process of code writing, it will inevitably encounter some headaches. The following describes how to return a negative number from the remainder of a PHP integer.
Let's look at an example.
The code is as follows:
$ Res = 16244799483;
Echo $ res %9999999;
// The output result is-5069794. the correct result is 4801107.
In fact, this is also a BUG in PHP. The most important thing is that PHP is a weak language. It has built-in machines to determine the user type.
But after all, the machine is a machine, and when an error is identified, it is like the above. so we need manual intervention.
So I want to use the following method to solve the problem of returning a negative number from the remainder of the PHP integer.
The code is as follows:
$ Res = floatval (16244799483 );
Var_dump ($ res %9999999 );
We can see that the result is still incorrect-5069794.
However, it is worth noting that the return value is of the int type.
I thought about the problem of returning a negative number from the remainder of the PHP integer.
PHP returns an integer by default.
And when you define $ res = 16244799483;
In fact, it has already exceeded. Therefore, we need to add the forced type conversion to the float type.
However, this is not enough because % is an integer.
Therefore, we need a function fmod for the float type.
Therefore, the final solution for returning a negative number from the remainder of the PHP integer is:
The code is as follows:
$ Res = floatval (16244799483 );
Var_dump (fmod ($ res, 9999999 ));
In this way, the problem of returning a negative number from the remainder of the PHP integer is solved .:)
Bytes. Next we will introduce how to get PHP integers...