Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does 15.5 mod 5 = 0?

Tags:

php

modulus

I understand 15 mod 5 = 0 because there is no remainder from the division.

But why does 15.5 mod 5 == 0 also? Isn't there .5 remaining?

$time = "15.5";
$interval = 5.0;
if($time % $interval == 0)
    echo "it's time!";
else
    echo "not time";

//Outputs: it's time!
like image 250
dukevin Avatar asked Jul 16 '12 01:07

dukevin


People also ask

Should I update to iOS 15.5 or wait?

It's also useful for getting friends/family to quickly pay their debts! And yet the most significant reason you should upgrade to iOS 15.5 is security. The official iOS 15.5 security page reveals no less than 34 security patches.

Why is the iOS 15.5 taking so long?

There is a huge possibility that the new update file is corrupted due to which your iPhone is stuck at iOS 15.5 estimating time remaining. It's better to delete this file from storage and try again installing the update from scratch. Go to Settings > General > iPhone Storage. locate the iOS version and tap it.

Does iOS 15.5 have bugs?

iOS 15.5 Issues. Unfortunately, most new releases also allow minor or more significant problems to slip through the beta testing phase. Any new bugs spotted in this release are listed below, along with available troubleshooting tips: Universal Control not working between MacBook Pro and iPad Pro.


1 Answers

From the PHP docs:

Operands of modulus are converted to integers (by stripping the decimal part) before processing.

Use fmod if you want to preserve decimal remainders. (Thanks for the link, Oli Charlesworth, wasn't aware that such a function existed.)

like image 94
Elliot Bonneville Avatar answered Oct 17 '22 00:10

Elliot Bonneville