Search code examples
phpnumbersdigits

Show more digits in PHP


Let's say I have:

echo 1/3;

And it print out only 0.33333333333333, can I get more digits?


Solution

  • Can use bcdiv

    echo bcdiv(1, 3, 20);
    

    The third argument

    is used to set the number of digits after the decimal place in the result. You can also set the global default scale for all functions by using bcscale().