如何将电话号码字符串转换为int或float,末尾没有0


How to covert string of phone number to int or float without .0 at the end?

数据库中的值为63906xxxxxxx,即电话号码。现在,如何拉这个数字正好12位,因为我有一个32位版本的PhP。

这是我的代码获取作为字符串:$contactNum = $ ngo_contactno;

        $numeric_indexed_array = array_values($contactNum);
        $n = $numeric_indexed_array[0];

dd ($ n);输出:"639063449729"

这是我的代码获得作为字符串转换为int:$contactNum = $ ngo_contactno;

        $numeric_indexed_array = array_values($contactNum);
        $n = $numeric_indexed_array[0];
        $number = (int) $n;
        dd($number);

输出:2147483647字符串变为浮动输出:639063449729.0

我想要的是整个数字639063449729,这样我就可以用它来传递给我的短信API。

不要将电话号码转换为整数或浮点数。在32位环境中,正整数的最大值是2^31,比2 000 000 000大一点。用32位来表示一个12位数简直是不可能的。也不要使用浮点数。具有有限精度的浮点数,因此您的电话号码可能四舍五入到下一个可表示的数字。

维基百科说:

在国际电话网中,电话的格式数字由ITU-T建议E.164标准化。这段代码指定整个号码应该是15位或更短的数字,和以国家/地区开头