2

我很难用这个等式让它返回正确的值。根据 Steam 的说法,等式Steam_community_number = (Last_part_of_steam_id * 2) + 76561197960265728 + Second_to_last_part_of_steam_id应该返回 64 位 Steam 社区 ID。目前,这个方程正在返回7.6561198012096E+16。方程应该返回76561198012095632,它在某种程度上与它已经返回的几乎相同。我如何将返回的 E+16 值转换为上面我在下面的代码中所述的正确值?谢谢。

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;
}

我正在调用这个函数$cid = convertSID("STEAM_0:0:25914952");

如果您想查看输出示例,请在此处查看:http: //joshua-ferrara.com/hkggateway/sidtester.php

4

1 回答 1

4

改变

return (string)$cid;

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

请注意,这将返回一个字符串,如果您对其进行任何数学运算,它将被转换回浮点数。要对大整数进行数学运算,请使用bc_math扩展名:http ://www.php.net/manual/en/book.bc.php

编辑:您的函数转换为使用 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;
}
于 2012-03-01T17:19:18.520 回答