Asked  7 Months ago    Answers:  5   Viewed   33 times

Derived from this question : (Java) How does java do modulus calculations with negative numbers?

Anywhere to force PHP to return positive 51?

Looking for a configuration setting to fix, instead hard-guessing

Or other math function like bcmath?

Not entire convinced by that java answer, as it does not take account of negative modulus -13+(-64) =?



If GMP is available, you can use gmp_mod

Calculates n modulo d. The result is always non-negative, the sign of d is ignored.


echo gmp_strval(gmp_mod('-13', '64')); // 51

Note that n and d have to be GMP number resources or numeric strings. Anything else won't work¹

echo gmp_strval(gmp_mod(-13, 64));
echo gmp_mod(-13, 64);

will both return -51 instead (which is a bug).

¹ running the above in this codepad, will produce 51 in all three cases. It won't do that on my development machine.

Wednesday, March 31, 2021
answered 7 Months ago

Well, I figured this out quite a long time ago: here's the answer. A guy made a workaround. First, he separate the macros files (VBA) from the sheet, then he left the PHPExcel "doing his thing", e then put it back (the macros!). It was enough for me! :D

Wednesday, March 31, 2021
answered 7 Months ago

Modulus returns the remainder, not a boolean value.

This code will resolve to true for 1, 3, 6, 9, ...

if (($k % 3 == 0) || $k==1 ) { echo '<div class="modcontainer">'; } 

This code will resolve to true for 1, 4, 7, 10, ...

if ($k % 3 == 1) { echo '<div class="modcontainer">'; } 
Wednesday, March 31, 2021
answered 7 Months ago

Should set the row height to 'auto' for row 1.

Wednesday, March 31, 2021
answered 7 Months ago

It's giving you the reminder of the division what you need is fmod,

fmodReturns the floating point remainder (modulo) of the division of the arguments

echo fmod(877.5, 1); // 0.5
Saturday, May 29, 2021
answered 5 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :