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 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)
  • ¥50 mac mini外接显示器 画质字体模糊