Guest User

Untitled

a guest
Jun 20th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.41 KB | None | 0 0
  1. round(3.78 * 5) / 5 = 3.8
  2.  
  3. function roundToNearestFraction( $number, $fractionAsDecimal )
  4. {
  5. $factor = 1 / $fractionAsDecimal;
  6. return round( $number * $factor ) / $factor;
  7. }
  8.  
  9. // Round to nearest fifth
  10. echo roundToNearestFraction( 3.78, 1/5 );
  11.  
  12. // Round to nearest third
  13. echo roundToNearestFraction( 3.78, 1/3 );
  14.  
  15. function round2($original) {
  16. $times5 = $original * 5;
  17. return round($times5) / 5;
  18. }
Add Comment
Please, Sign In to add comment