Question about the number_format function of php. echo number_format (88899626759579787, 0 ,'','');
Why is the output 88899626759579792?
Reply to discussion (solution)
I am also a newbie. I asked my mother, and she said the format was wrong!
From http://www.w3school.com.cn/php/func_string_number_format.asp
Because your environment should be 32-bit, to indicate your above 88899626759579787 numbers, you must use the floating point type, and the floating point type accuracy cannot be guaranteed.
You can see through this example.
Echo PHP_INT_MAX; // The maximum integer var_dump (number_format (88899626759579700, 0, '','') that can be expressed by the php integer ,'',''));
Do you hesitate to write the environment when posting.
The development environment is win7 64bit, and the production environment is centOS 64bit.
Or the same error.
Is there a solution?
This is a number taken from other APIs. if it is directly displayed, the scientific notation is displayed.
The strval function is not easy to use.
Thank you!
Because your environment should be 32-bit, to indicate your above 88899626759579787 numbers, you must use the floating point type, and the floating point type accuracy cannot be guaranteed.
You can see through this example.
Echo PHP_INT_MAX; // The maximum integer var_dump (number_format (88899626759579700, 0, '','') that can be expressed by the php integer ,'',''));
In addition, json data is returned by the api. I use json_decode (), as if it is automatically converted to the numeric type.
Php is also available in the 64-bit version ..
Have you tried to change it according to #1?
Have you tried to change it according to #1?
16 digits are good.
The php long type cannot represent such a large positive number.
Php development organization has never released a 64-bit version for win
If there are conditions, it is best to upgrade to php5.4 +, because when php is in 5.4, add a parameter to json_decode.
5.4.0 The options parameter was added.
Bitmask of JSON decode options. Currently only JSON_BIGINT_AS_STRING is supported (default is to cast large integers as floats)
The above routine will output: float (1.2345678901235E + 19) string (20) "12345678901234567890"
If the update fails, we recommend that you add a special identifier to the full text that exceeds the int integer length. for example
{"A": "12345678901234567890 "}
You can replace the regular expression
{"A": "_ 12345678901234567890 "}
After json_decode is complete, remove the _ identifier.
If there are conditions, it is best to upgrade to php5.4 +, because when php is in 5.4, add a parameter to json_decode.
5.4.0 The options parameter was added.
Bitmask of JSON decode options. Currently only JSON_BIGINT_AS_STRING is supported (default is to cast large integers as floats)
The above routine will output: float (1.2345678901235E + 19) string (20) "12345678901234567890"
If the update fails, we recommend that you add a special identifier to the full text that exceeds the int integer length. for example
{"A": "12345678901234567890 "}
You can replace the regular expression
{"A": "_ 12345678901234567890 "}
After json_decode is complete, remove the _ identifier.
Thank you for your reply.
The solution has been fixed. the solution is similar to that for upgrading.
The data obtained in the development environment is out of bounds, and there will be no cross-border issues in the actual production environment.
Therefore, the string parsing method is used.
Thanks again!
Close the post!