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.  
  14. $amount = "99.82000000000001";
  15. $amount = round_up($amount, 3);
  16. echo $amount;
Success #stdin #stdout 0.02s 25664KB
stdin
Standard input is empty
stdout
99.821