14

How can i do modulo arithmetic with decimal value since PHP only can do modulo with integer?

Example case:

 echo 1.92 % 1000; // (int) 1, expected result should be 1.92 

is there any library to do this correctly?

More info about this modulo arithmetic problem: https://bugs.php.net/bug.php?id=34399

3
  • 1
    It's not a bug, please look up what modulus is in arithmetic. Commented Nov 26, 2012 at 16:42
  • @N.B. I didn't say this is a bug. I aware of PHP Capability about this. what i looking for is solution because this PHP Limitless. Commented Nov 26, 2012 at 16:46
  • 3
    Why there is people want to close this question? i believe there is much people will also looking solution for this? @_@ Commented Nov 26, 2012 at 16:46

2 Answers 2

39

There is also a floating point fmod() function

echo fmod(1.92, 1000) 
Sign up to request clarification or add additional context in comments.

3 Comments

@GusDeCooL You should accept an answer if it was helpful and solved Your problem.
@shadyyx Yes i want to accept it, but following stackoverflow policy i need to wait 6 minutes. LOL.
Down voted by mistake sorry that's my bad wanted to up vote =D
6

http://php.net/manual/en/function.fmod.php

I think you wanted this one, this returns float result?

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.