Questions about the number_format function of php

Source: Internet
Author: User
Question about the number_format function of php. echo & nbsp; number_format (88899626759579787, & nbsp; 0, & nbsp;, & nbsp;); why is the output 88899626759579792 & nbsp ;? About the number_format function of php.
Echo number_format (88899626759579787, 0 ,'','');
Why is the output 88899626759579792?

Share:


------ 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
------ Solution --------------------
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 that the php integer can represent

Var_dump (number_format (88899626759579700, 0 ,'',''));

------ Solution --------------------
Have you tried to change it according to #1?
------ Solution --------------------
The php long type cannot represent such a large positive number.

Php development organization has never released a 64-bit version for win

------ Solution --------------------
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.

Reference
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)



$ Json = '000000 ';

Var_dump (json_decode ($ json ));
Var_dump (json_decode ($ json, false, 512, JSON_BIGINT_AS_STRING ));

?>

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.

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.