fork download
  1. <?php
  2.  
  3. function round_up ($value, $places=0) {
  4. if ($places < 0) { $places = 0; }
  5. $mult = pow(10, $places);
  6. $decimal_length = strlen(substr(strrchr($value, "."), 1));
  7. if($decimal_length <= $places) {
  8. return $value;
  9. }
  10. return ceil($value * $mult) / $mult;
  11. }
  12.  
  13. $val = "2.522";
  14. echo round_up(round_up($val, 2), 2);
Success #stdin #stdout 0.03s 26100KB
stdin
Standard input is empty
stdout
2.53