dongshuo6185 2012-03-01 17:15
浏览 148
已采纳

PHP数学公式,E + 16?

I'm having trouble with this equation in getting it to return the proper value. According to Steam, the equation Steam_community_number = (Last_part_of_steam_id * 2) + 76561197960265728 + Second_to_last_part_of_steam_id Should return the 64 bit Steam Community ID. Currently, this equation is returning 7.6561198012096E+16. The equation should be returning 76561198012095632 which in a way is almost the same as what it is already returning. How would I convert the returned E+16 value to the correct value as stated above in my code below? Thanks.

function convertSID($steamid) {
    if ($steamid == null) { return false; }
    //STEAM_X:Y:Z
    //W=Z*2+V+Y
    //Z, V, Y
    //Steam_community_number = (Last_part_of_steam_id * 2) + 76561197960265728 + Second_to_last_part_of_steam_id
    if (strpos($steamid, ":1:")) {
        $Y = 1;
    } else {
        $Y = 0;
    }
    $Z = substr($steamid, 10);
    $Z = (int)$Z;
    echo "Z: " . $Z . "</br>";
    $cid = ($Z * 2) + 76561197960265728 + $Y;
    echo "Equation: (" . $Z . " * 2) + 76561197960265728 + " . $Y . "<br/>";
    return (string)$cid;
}

And I am calling this function with $cid = convertSID("STEAM_0:0:25914952");

If you would like to see an example of the output, check here: http://joshua-ferrara.com/hkggateway/sidtester.php

  • 写回答

1条回答 默认 最新

  • doupo6967 2012-03-01 17:19
    关注

    Change

    return (string)$cid;
    

    to

    return number_format($cid,0,'.','');
    

    Be aware that this will return a string, and if you do any math on it, it will be converted back to float. To do math on large integers use bc_math extension: http://www.php.net/manual/en/book.bc.php

    edit: your function converted to use bcmath:

    function convertSID($steamid) {
        if ($steamid == null) { return false; }
        //STEAM_X:Y:Z
        //W=Z*2+V+Y
        //Z, V, Y
        //Steam_community_number = (Last_part_of_steam_id * 2) + 76561197960265728 + Second_to_last_part_of_steam_id
    
        $steamidExploded = explode(':',$steamid);
        $Y = (int)steamidExploded[1];
        $Z = (int)steamidExploded[2];
        echo "Z: " . $Z . "</br>";
        $cid = bcadd('76561197960265728 ',$Z * 2 + $Y);
        echo "Equation: (" . $Z . " * 2) + 76561197960265728 + " . $Y . "<br/>";
        return $cid;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看