PHP数学公式,E + 16?
问题描述:
我在使这个公式返回正确的值时遇到了麻烦。根据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值转换为以上代码中所述的正确值?谢谢。PHP数学公式,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
答
变化
return (string)$cid;
到
return number_format($cid,0,'.','');
请注意,这将返回一个字符串,并且如果您对其执行任何数学运算,它将转换回浮点数。 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;
}
相关:要在大的整数使用
bc_math
扩展做数学[如何对PHP 64位整数?](HTTP://计算器。 com/questions/864058/how-to-have-64-bit-integer-on-php) – Orbling 2012-03-01 17:18:06