I have a variable $newTime, which is time in seconds made by mktime(), and I want to convert it into number of days.
In this case it is over 86.400 (which is a number of seconds in a day), and I try to divide it by 86.400 to get number of days (rounded).
But sometimes I get:
Case 1: 87951 / 86400 = 1.0179513888 (1 day ago)
Case 2: 156257 / 86400 = 1.8085300925 (2 days ago)
and sometimes:
Case 1: 87986 / 86400 = 1 (Should be 1 day ago)
Case 2: 156292 / 86400 = 1 (Should be 2 days ago)
This is the code:
$newTime = round(bcdiv($newTime, bcmul("24", bcmul("60", "60"))),0);
When I don't use bcmath, just the regular math ($newTime / (60*60*24)), I get floating results every time.
Have you set the scale using
bcscale? If it is set to0, it could explain the behaviour. Please, try to callbcscale(100)before your computation;