Web Analytics Made Easy -
StatCounter Finding a Remainder? - CodingForum

Announcement

Collapse
No announcement yet.

Finding a Remainder?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Finding a Remainder?

    Hi all, I am writing some PHP code and I am looking to find if a number has a fractional part to it. For example I want to return the .34 of the number 12.34.

    I thought this could be done with the modulus operator but I can't get it to work. With windows calculator I do "12.34 mod 1" and it returns "0.34" but if I do:
    PHP Code:
    echo 12.34 1
    in PHP it returns zero. Anyone have any ideas?

  • #2
    PHP Code:
    <?php
    $a 
    4.72;
    list (
    $whole$dec) = explode('.'$a);
    echo 
    $dec
    ?>

    Comment


    • #3
      Solved

      Thanks for the reply but further research has shown that PHP has a function to do this for me.

      PHP Code:
      $output fmod(12.341); 
      $output would contain "0.34';

      Thanks again for an alternate way of acheiving this and the fast reply!

      Comment

      Working...
      X