fork download
  1. <?php
  2.  
  3. // your code goes here
  4.  
  5. function round_up ($value, $places=0) {
  6. if ($places < 0) { $places = 0; }
  7. $mult = pow(10, $places);
  8. $decimal_length = strlen(substr(strrchr($value, "."), 1));
  9. if($decimal_length <= $places) {
  10. return $value;
  11. }
  12. return ceil($value * $mult) / $mult;
  13. }
  14.  
  15.  
  16. $price = 22.4;
  17. $vat_value = 0.1;
  18. $price_to_pay = $price + ($price * $vat_value);
  19. $price_to_pay = round_up($price_to_pay, 3);
  20.  
  21. var_dump($price_to_pay);
  22. $data = ['amount' => (string)$price_to_pay];
  23. echo json_encode($data);
Success #stdin #stdout 0.02s 25872KB
stdin
Standard input is empty
stdout
float(24.64)
{"amount":"24.64"}