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"; }

Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).

VersionSystem time (s)User time (s)Memory (MiB)
8.4.130.0120.00917.85
8.4.120.0180.00420.51
8.4.110.0130.00620.64
8.4.100.0080.00019.01
8.4.90.0090.01320.37
8.4.80.0070.01220.05
8.4.70.0050.00318.04
8.4.60.0130.00818.73
8.4.50.0120.00918.79
8.4.40.0100.01018.11
8.4.30.0160.00324.00
8.4.20.0100.01019.93
8.4.10.0040.00419.43
8.3.260.0090.01116.92
8.3.250.0110.00819.12
8.3.240.0050.00519.19
8.3.230.0070.01417.31
8.3.220.0120.01017.75
8.3.210.0120.00817.17
8.3.200.0050.00417.11
8.3.190.0100.00117.64
8.3.180.0120.00519.10
8.3.170.0110.00817.67
8.3.160.0070.01116.97
8.3.150.0060.01017.63
8.3.140.0030.01617.05
8.3.130.0060.00318.70
8.3.120.0030.00720.93
8.3.110.0320.00716.88
8.3.100.0330.00516.82
8.3.90.0280.00317.02
8.3.80.0290.00016.80
8.3.70.0270.01016.78
8.3.60.0210.00717.04
8.3.50.0210.00816.90
8.3.40.0200.00817.89
8.3.30.0290.00417.99
8.3.20.0170.00917.89
8.3.10.0220.00217.96
8.3.00.0130.00318.87
8.2.290.0090.00617.21
8.2.280.0080.00316.91
8.2.270.0130.00617.02
8.2.260.0150.00317.10
8.2.250.0060.00318.82
8.2.240.0060.00317.09
8.2.230.0160.00516.69
8.2.220.0160.00616.81
8.2.210.0140.00816.92
8.2.200.0190.00716.88
8.2.190.0230.00116.82
8.2.180.0230.00716.76
8.2.170.0250.00817.83
8.2.160.0260.00617.76
8.2.150.0270.00617.90
8.2.140.0200.00717.80
8.2.130.0240.00617.80
8.2.120.0250.00518.03
8.2.110.0280.00517.85
8.2.100.0180.01617.84
8.2.90.0240.00617.95
8.2.80.0190.01117.91
8.2.70.0250.00618.05
8.2.60.0220.00717.90
8.2.50.0270.00717.77
8.2.40.0220.00918.11
8.2.30.0180.00817.96
8.2.20.0200.00517.88
8.2.10.0200.01418.00
8.2.00.0200.00217.93
8.1.330.0130.00716.75
8.1.320.0100.01016.30
8.1.310.0050.00318.54
8.1.300.0030.00616.54
8.1.290.0270.00216.21
8.1.280.0210.00516.32
8.1.270.0270.00617.81
8.1.260.0250.00617.70
8.1.250.0220.00417.84
8.1.240.0180.00217.88
8.1.230.0260.00117.73
8.1.220.0160.00617.78
8.1.210.0260.00217.59
8.1.200.0190.00717.54
8.1.190.0130.00717.70
8.1.180.0230.01017.38
8.1.170.0170.00417.71
8.1.160.0120.00617.63
8.1.150.0280.00817.63
8.1.140.0300.00717.59
8.1.130.0260.00717.69
8.1.120.0310.00217.56
8.1.110.0200.00817.50
8.1.100.0250.00417.54
8.1.90.0360.00217.52
8.1.80.0250.00717.61
8.1.70.0260.00817.57
8.1.60.0290.00217.63
8.1.50.0200.00417.59
8.1.40.0210.00517.59
8.1.30.0220.00817.65
8.1.20.0180.00817.65
8.1.10.0170.00417.71
8.1.00.0150.00617.57

preferences:
26.77 ms | 403 KiB | 5 Q