Convert a big integer to a full string in PHP

前端 未结 4 1270
失恋的感觉
失恋的感觉 2020-12-03 23:12

I\'ve been searching for a while now, but what I can find is not what I search for. I need to convert an integer value, that may be very huge, to a string. Sounds e

4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-03 23:29

    UPDATE: Found the next post:

    // strval() will lose digits around pow(2,45);
    echo pow(2,50); // 1.1258999068426E+015
    echo (string)pow(2,50); // 1.1258999068426E+015
    echo strval(pow(2,50)); // 1.1258999068426E+015
    
    // full conversion
    printf('%0.0f',pow(2,50)); // 112589906846624
    echo sprintf('%0.0f',pow(2,50)); // 112589906846624
    

    Use printf or sprintf.

提交回复
热议问题