Echo a very large number

后端 未结 5 2175
抹茶落季
抹茶落季 2021-01-01 21:30

I have a unusual problem which I have no idea how to solve.

I have a JSON file, where a application id is stored, namely the following:

\"app_id\": \         


        
相关标签:
5条回答
  • 2021-01-01 21:59

    A quick and dirty solution would be to add some character at the beginning or end of your number to force PHP to treat it as a string. Maybe intstead of "363924477024846" use "z363924477024846" and then remove the z when you need to use it. Obviously append this before you send it.

    0 讨论(0)
  • 2021-01-01 22:01

    If you can change the JSON file contents, have you tried wrapping the application ID in quotes, like so:

    "app_id": "'363924477024846'"
    

    As clentfort has said, you're exceeding the max value for a 32bit integer (~2.1bn signed)

    0 讨论(0)
  • 2021-01-01 22:19

    I had the same problem here: Simply use phps number_format function, which solves this issue:

    $number = "363924477024846";
    echo number_format($number, 0, '', '');
    
    // 363924477024846
    
    0 讨论(0)
  • 2021-01-01 22:19

    It looks like json_decode has an option to treat big integers as strings.

    json_decode($json, false, 512, JSON_BIGINT_AS_STRING)
    
    0 讨论(0)
  • 2021-01-01 22:24

    try casting it to a string

    echo((string)$theNumber);
    
    0 讨论(0)
提交回复
热议问题