Question

echo bcdiv(0.0001, 86400, 30);

This code echos: 0.000000001157407407407407407407

echo bcdiv(0.00001, 86400, 30);

And this code echos: 0.000000000000000000000000000000

Why is that? Is there a minimum value for both operands? I need to divide 0.00000001 by 86400, is this possible?

Here's the doc for bcdiv: http://us2.php.net/manual/en/function.bcdiv.php

Was it helpful?

Solution

bc library works with strings: don't make assumptions about its internal casting of integer arguments, but pass strings directly

echo bcdiv('0.00001', '86400', 30);

gives

0.000000000115740740740740740740
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top