troubleshooting Question

Modulus but not full ints

Avatar of tonelm54
tonelm54 asked on
2 Comments1 Solution37 ViewsLast Modified:
Im trying to figure out how to modulus with decimal places.
$totTime = 1;
$modDivisor = 3 * 0.25;

echo "Total Time: " . $totTime . "<br/>";
echo "Divosor: " . $modDivisor . "<br/>";
echo $totTime % $modDivisor;

But keep getting

FATAL ERROR Uncaught DivisionByZeroError: Modulo by zero in /home4/phptest/public_html/code.php70(5) : eval()'d code:7 Stack trace: #0 /home4/phptest/public_html/code.php70(5): eval() #1 {main} thrown on line number 7

The issue I have is the "3*0.25" can be "2*0.25" or "5*0.25" or any other number, so I cant multiply into full number

For example:-
$totTime = 1;
$modDivisor = 5 * 0.25;

echo "Total Time: " . $totTime . "<br/>";
echo "Divosor: " . $modDivisor . "<br/>";
echo $totTime % $modDivisor;

Should give 0.25, but instead gives 0

Any ideas?

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 2 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros