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"; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 11
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 11
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 11
2 jumps found. (Code = 77) Position 1 = 14, Position 2 = 23
Branch analysis from position: 14
2 jumps found. (Code = 78) Position 1 = 15, Position 2 = 23
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
Branch analysis from position: 23
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 23
Branch analysis from position: 11
filename:       /in/o58KM
function name:  (null)
number of ops:  25
compiled vars:  !0 = $test, !1 = $num
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   34     0  E >   ASSIGN                                                   !0, <array>
   51     1      > FE_RESET_R                                       $3      !0, ->11
          2    > > FE_FETCH_R                                               $3, !1, ->11
   52     3    >   ECHO                                                     !1
          4        ECHO                                                     '%3A+'
          5        INIT_FCALL                                               'scientific2decimal'
          6        SEND_VAR                                                 !1
          7        DO_FCALL                                      0  $4      
          8        ECHO                                                     $4
          9        ECHO                                                     '%0A'
   51    10      > JMP                                                      ->2
         11    >   FE_FREE                                                  $3
   54    12        ECHO                                                     '%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%0A'
   55    13      > FE_RESET_R                                       $5      !0, ->23
         14    > > FE_FETCH_R                                               $5, !1, ->23
   56    15    >   ECHO                                                     !1
         16        ECHO                                                     '%3A+'
         17        INIT_FCALL                                               'number2decimal'
         18        SEND_VAR                                                 !1
         19        DO_FCALL                                      0  $6      
         20        ECHO                                                     $6
         21        ECHO                                                     '%0A'
   55    22      > JMP                                                      ->14
         23    >   FE_FREE                                                  $5
   57    24      > RETURN                                                   1

Function scientific2decimal:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 11
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
2 jumps found. (Code = 43) Position 1 = 26, Position 2 = 33
Branch analysis from position: 26
1 jumps found. (Code = 42) Position 1 = 35
Branch analysis from position: 35
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 33
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/o58KM
function name:  scientific2decimal
number of ops:  43
compiled vars:  !0 = $num, !1 = $decimal_separator, !2 = $thousands_separator, !3 = $matches, !4 = $decimals, !5 = $sign, !6 = $exponent, !7 = $actual_decimals, !8 = $number_of_decimals
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      '.'
          2        RECV_INIT                                        !2      '%2C'
    5     3        INIT_FCALL                                               'preg_match'
          4        SEND_VAL                                                 '%21%5Cd%2B%28%5C.%28%5Cd%2B%29%29%3Fe%28%5B%2B-%5D%3F%29%28%5Cd%2B%29%24%21i'
          5        SEND_VAR                                                 !0
          6        SEND_REF                                                 !3
          7        DO_ICALL                                         $9      
          8        BOOL_NOT                                         ~10     $9
          9      > JMPZ                                                     ~10, ->11
    6    10    > > RETURN                                                   !0
    9    11    >   QM_ASSIGN                                        ~11     !3
         12        FETCH_LIST_R                                     $12     ~11, 2
         13        ASSIGN                                                   !4, $12
         14        FETCH_LIST_R                                     $14     ~11, 3
         15        ASSIGN                                                   !5, $14
         16        FETCH_LIST_R                                     $16     ~11, 4
         17        ASSIGN                                                   !6, $16
         18        FREE                                                     ~11
   10    19        JMP_SET                                          ~18     !5, ->21
         20        QM_ASSIGN                                        ~18     '%2B'
         21        ASSIGN                                                   !5, ~18
   11    22        STRLEN                                           ~20     !4
         23        ASSIGN                                                   !7, ~20
   12    24        IS_IDENTICAL                                             !5, '%2B'
         25      > JMPZ                                                     ~22, ->33
   13    26    >   INIT_FCALL                                               'max'
         27        SEND_VAL                                                 0
         28        SUB                                              ~23     !7, !6
         29        SEND_VAL                                                 ~23
         30        DO_ICALL                                         $24     
         31        ASSIGN                                                   !8, $24
   12    32      > JMP                                                      ->35
   15    33    >   ADD                                              ~26     !6, !7
         34        ASSIGN                                                   !8, ~26
   17    35    >   INIT_FCALL                                               'number_format'
         36        SEND_VAR                                                 !0
         37        SEND_VAR                                                 !8
         38        SEND_VAR                                                 !1
         39        SEND_VAR                                                 !2
         40        DO_ICALL                                         $28     
         41      > RETURN                                                   $28
   18    42*     > RETURN                                                   null

End of function scientific2decimal

Function number2decimal:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 9
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
2 jumps found. (Code = 43) Position 1 = 20, Position 2 = 21
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 21
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/o58KM
function name:  number2decimal
number of ops:  45
compiled vars:  !0 = $number, !1 = $decimal_separator, !2 = $thousands_separator, !3 = $parts, !4 = $base, !5 = $exponent, !6 = $number_of_decimals
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      '.'
          2        RECV_INIT                                        !2      '%2C'
   22     3        INIT_FCALL                                               'is_numeric'
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                         $7      
          6        BOOL_NOT                                         ~8      $7
          7      > JMPZ                                                     ~8, ->9
   23     8    > > RETURN                                                   !0
   25     9    >   INIT_FCALL                                               'explode'
         10        SEND_VAL                                                 'e'
         11        INIT_FCALL                                               'strtolower'
         12        SEND_VAR                                                 !0
         13        DO_ICALL                                         $9      
         14        SEND_VAR                                                 $9
         15        DO_ICALL                                         $10     
         16        ASSIGN                                                   !3, $10
   26    17        COUNT                                            ~12     !3
         18        IS_NOT_EQUAL                                             ~12, 2
         19      > JMPZ                                                     ~13, ->21
   27    20    > > RETURN                                                   !0
   29    21    >   QM_ASSIGN                                        ~14     !3
         22        FETCH_LIST_R                                     $15     ~14, 0
         23        ASSIGN                                                   !4, $15
         24        FETCH_LIST_R                                     $17     ~14, 1
         25        ASSIGN                                                   !5, $17
         26        FREE                                                     ~14
   30    27        MUL                                              ~19     !5, -1
         28        STRLEN                                           ~20     !4
         29        ADD                                              ~21     ~19, ~20
         30        INIT_FCALL                                               'strrpos'
         31        SEND_VAR                                                 !4
         32        SEND_VAL                                                 '.'
         33        DO_ICALL                                         $22     
         34        SUB                                              ~23     ~21, $22
         35        SUB                                              ~24     ~23, 1
         36        ASSIGN                                                   !6, ~24
   31    37        INIT_FCALL                                               'number_format'
         38        SEND_VAR                                                 !0
         39        SEND_VAR                                                 !6
         40        SEND_VAR                                                 !1
         41        SEND_VAR                                                 !2
         42        DO_ICALL                                         $26     
         43      > RETURN                                                   $26
   32    44*     > RETURN                                                   null

End of function number2decimal

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
139.42 ms | 1022 KiB | 22 Q