3v4l.org

run code in 300+ PHP versions simultaneously
<?php function money_round ($amount) { # convert to string $string = (string)$amount; ## find out if negative ## if (substr($string, 0, 1) == '-') { $negative = true; $string = substr($string, 1, strlen($string) - 1); } else { $negative = false; } # if there's no decimal point add one on the end if (substr_count($string, '.') == 0) { $string .= '.'; } # add a few trailing '0's in case there aren't enough there already $string .= '000'; # find the decimal point $dotpos = strpos($string, '.'); # separate pounds $pounds = substr($string, 0, $dotpos); # separate pence $pence = substr($string, $dotpos + 1, 2); # find out how many tenths of a penny $tenths = substr($string, $dotpos + 3, 1); if ($tenths >= 5) { $pence++; if ($pence == 100) { $pence = '0'; $pounds++; } if ($pence < 10) { $pence = '0' . $pence; } } if ($negative) { return '-' . $pounds . '.' . $pence; } else { return $pounds . '.' . $pence; } } echo money_round(33333.333333333);
Output for git.master, git.master_jit, rfc.property-hooks
33333.33

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
48.57 ms | 401 KiB | 8 Q