Search code examples
phpsqrt

Php sqrt function returns wrong number


sqrt(0.0000000185); returns 0.00013601470. This is ok

sqrt(0.0000000065); returns 8.06225774. This is wrong. It had to be 0.000080622577483

How to fix this?

Thanks


Solution

  • You can use the Mathematical Extensions BC Math

    http://php.net/manual/en/function.bcsqrt.php

    echo bcsqrt('0.0000000065',20); //Result 0.00008062257748298549

    Here the number has to be an string!

    Note: The basic mathematical functions of php arent that nice...

    Have a nice day.