2

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

Josh Ferrara
  • 757
  • 2
  • 9
  • 25
  • Related: [how to have 64 bit integer on PHP?](http://stackoverflow.com/questions/864058/how-to-have-64-bit-integer-on-php) – Orbling Mar 01 '12 at 17:18

1 Answers1

4

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;
}
Mchl
  • 61,444
  • 9
  • 118
  • 120
  • 1
    Note, as per my link above, if you're using a 64bit version of PHP, you might be able to get away with doing it using normal operators. – Orbling Mar 01 '12 at 17:35
  • That's correct of course, however spotting a 64b installation of PHP in the wild is currently no less difficult than spotting an albino tiger – Mchl Mar 01 '12 at 17:37