3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * Get the decimals value * * @param $value * @param $min - min decimals * @return int */ function get_decimals($value = 0, $min = 2) { if ($value === '0.00') { return $min; } for ($i = strlen($value); $i >= $min; $i--) { if (strstr($value, '0.'.str_repeat('0', $i), true) !== false) { return $i+$min; } } return $min; } $values = [ '0.000000000000000000000000000000000000000000000000000000001', # ¯\_(ツ)_/¯ '0.002117647058', '0.00000000001', '2.117647058', '999.0', '0.1', '0.00', '0.0', '0' ]; foreach ($values as $value) { echo number_format($value, get_decimals($value, 5)).PHP_EOL; }
Output for git.master_jit, git.master, rfc.property-hooks
0.0000000000000000000000000000000000000000000000000000000010000 0.00212 0.000000000010000 2.11765 999.00000 0.10000 0.00000 0.00000 0.00000

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:
63.94 ms | 405 KiB | 5 Q