Search code examples
phpnumberscode-readabilityhuman-readable

Is there a character I can use to improve large number legibility in PHP code?


In Perl code, you can put underscores in large numbers to improve legibility. For example, the number 123456789 is equivalent to 123_456_789, which helps the coder understand what number it represents.

Is there a character in PHP that I can use for the same purpose? I have tried commas and underscores, but neither of them work.


Solution

  • Mark Baker is right, but If you strongly want

    function f() {
        $f = 0;
        $args = func_get_args();
        foreach ($args as $arg) {
            $f = $f*1000+$arg;
        }
        return($f);
    }
    
    $i = f(17,123.81);
    echo $i;
    

    result 17123.81