Posted By

bwangila on 01/13/11


Tagged

number


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

AllKnightAccess


PHP Split a number into the integer and fraction parts


 / Published in: PHP
 

I needed to split a decimal number into the integer part and the fraction part and save both of them in different variables

  1. function split_number ( $number )
  2. {
  3. //Convert any entered number into a float
  4. $number = number_format ( $number, 1 );
  5.  
  6. //Get the integer part
  7. $intpart = floor ( $number );
  8.  
  9. //Get the fraction part
  10. $fraction = $number - $intpart;
  11. }

Report this snippet  

You need to login to post a comment.