Questions about PHP's Number_format function

Source: Internet
Author: User
Questions about PHP's Number_format function.
Echo Number_format (88899626759579787, 0, ', ');
Why does the output result be 88899626759579792?

Share to:


------Solution--------------------
I am also a novice, asked the next degree Niang, she said, the format is wrong!
Originated from http://www.w3school.com.cn/php/func_string_number_format.asp
------Solution--------------------
Because your environment should be 32-bit, to show you the above 88899626759579787 number, to use floating-point type, and the precision of floating-point type is no way to guarantee.

You can tell by this example.


Echo Php_int_max; Maximum number of integers that can be represented by the shaping of PHP

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

------Solution--------------------
Have you ever tried to change it by #1 say?
------Solution--------------------
Out of bounds, the long type of PHP cannot represent that large positive number

PHP Development organization has never released a 64-bit version of for win

------Solution--------------------
If there is a condition, it would be better to upgrade to php5.4+, because PHP adds a parameter to Json_decode at 5.4.

Reference
5.4.0 The options parameter was added.

Bitmask of JSON decode options. Currently only json_bigint_as_string are supported (default is to cast large integers as floats)



$json = ' 12345678901234567890 ';

Var_dump (Json_decode ($json));
Var_dump (Json_decode ($json, False, json_bigint_as_string));

?>

The above routines will output:
Float (1.2345678901235E+19)
String (20) "12345678901234567890"


If you cannot upgrade, we recommend that you first add a special identifier to the full numeric text that exceeds the int shape length first, for example
{"A": "12345678901234567890"}
Can be replaced by regular
{"A": "__12345678901234567890"}
When the Json_decode is finished, then the __ logo is removed
  • Related Article

    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.