3v4l.org

run code in 300+ PHP versions simultaneously
<?php function scientific2decimal($num, $decimal_separator = ".", $thousands_separator = ",") { if (!preg_match('!\d+(\.(\d+))?e([+-]?)(\d+)$!i', $num, $matches)) { return $num; } list(,,$decimals, $sign, $exponent) = $matches; $sign = $sign ?: "+"; $actual_decimals = strlen($decimals); if ($sign === '+') { $number_of_decimals = max(0, $actual_decimals - $exponent); } else { $number_of_decimals = $exponent + $actual_decimals; } return number_format($num, $number_of_decimals, $decimal_separator, $thousands_separator); } function number2decimal($number, $decimal_separator = ".", $thousands_separator = ",") { if (!is_numeric($number)) { return $number; } $parts = explode('e', strtolower($number)); if (count($parts) != 2) { return $number; } [$base, $exponent] = $parts; $number_of_decimals = -$exponent + strlen($base) - strrpos($base, '.') - 1; return number_format($number, $number_of_decimals, $decimal_separator, $thousands_separator); } $test = [ 'aaa', 'eee', '123ert', 7, 1e0, 0.000021, '1e3', '1.1337228E-3', '1.1337228E-6', '236.234e-5', '1.0002E3', '1.13372223434E+6', '2.133333E-5', 123456789842794767576576, ]; foreach ($test as $num) { echo $num, ": ", scientific2decimal($num), "\n"; } echo "=============\n"; foreach ($test as $num) { echo $num, ": ", number2decimal($num), "\n"; }
Output for git.master_jit, git.master, rfc.property-hooks
aaa: aaa eee: eee 123ert: 123ert 7: 7 1: 1 2.1E-5: 0.000021 1e3: 1,000 1.1337228E-3: 0.0011337228 1.1337228E-6: 0.0000011337228 236.234e-5: 0.00236234 1.0002E3: 1,000.2 1.13372223434E+6: 1,133,722.23434 2.133333E-5: 0.00002133333 1.2345678984279E+23: 123,456,789,842,794,775,576,576 ============= aaa: aaa eee: eee 123ert: 123ert 7: 7 1: 1 2.1E-5: 0.000021 1e3: 1,000 1.1337228E-3: 0.0011337228 1.1337228E-6: 0.0000011337228 236.234e-5: 0.00236234 1.0002E3: 1,000.2 1.13372223434E+6: 1,133,722.23434 2.133333E-5: 0.00002133333 1.2345678984279E+23: 123,456,789,842,789,994,070,016

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:
53.27 ms | 407 KiB | 5 Q