3v4l.org

run code in 300+ PHP versions simultaneously
<?php $digits = 10; foreach([7887.0000000000000000, 8667887.0000000000000000, 0.0786451, 1.0786451] as $lastPrice) { $price = number_format($lastPrice, 16, '.', ''); $price = ltrim($price, '-'); $price = rtrim($price, '0'); list($d, $s) = explode('.', $price); var_dump($price); var_dump([$d, $s]); if ($d !== '0') { $round = $digits - strlen($d); } else { $round = $digits + strlen($s) - strlen(ltrim($s, '0')); } var_dump($round); } return; foreach ([7887.0000000000000000, 0.0786451] as $price) { $maxDigits = 5; $log = floor(round(log($price) / M_LN10, 10)); var_dump($log); var_dump((10 ** ($maxDigits - $log))); }
Output for git.master_jit, git.master, rfc.property-hooks
string(5) "7887." array(2) { [0]=> string(4) "7887" [1]=> string(0) "" } int(6) string(8) "8667887." array(2) { [0]=> string(7) "8667887" [1]=> string(0) "" } int(3) string(9) "0.0786451" array(2) { [0]=> string(1) "0" [1]=> string(7) "0786451" } int(11) string(18) "1.0786450999999999" array(2) { [0]=> string(1) "1" [1]=> string(16) "0786450999999999" } int(9)

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:
68.7 ms | 402 KiB | 8 Q