php modulo return wrong result

前端 未结 4 708
我寻月下人不归
我寻月下人不归 2021-01-14 07:42

I got problem with this code:

if (!empty($_GET[ \"lic\" ])) $lic = $_GET[ \"lic\" ]; else $e = true;
echo ($lic % 11);

When I post 89

相关标签:
4条回答
  • 2021-01-14 08:24

    Use fmod:

    echo fmod(8911076856, 11);
    
    0 讨论(0)
  • 2021-01-14 08:24

    Did you tried this:

    if (!empty($_GET[ "lic" ])) $lic = intval($_GET[ "lic" ]); else $e = true;

    echo ($lic % 11);

    0 讨论(0)
  • 2021-01-14 08:32

    This is most likely being caused because the number you're posting is higher than PHP_INT_MAX, which is 9223372036854775807 on most 64-bit systems AFAIK. If you're using a 32-bit system (which I expect you are), it's probably 2147483647.

    0 讨论(0)
  • 2021-01-14 08:33

    The value "8911076856" is probably above the maximum integer value of your system.

    echo ((int)8911076856);
    

    My result is 321142264 on my 32 Bit system.

    0 讨论(0)
提交回复
热议问题