PHP Split a number into the integer and fraction parts


/ Published in: PHP
Save to your folder(s)

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


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.