3v4l.org

run code in 300+ PHP versions simultaneously
<?php function numericToStringDecimal($number, $nb_decimal = 2) { $int_part = (int)$number; $dec_part = $number - $int_part; $dec_len = strlen($dec_part) - 2; $dec_len = ($dec_len > 0) ? $dec_len : 0; if ($dec_len < $nb_decimal) { $string = number_format($number, $dec_len, ',', ' '); if (str_contains($string, ',') === false) { $string .= ','; } for ($i = $dec_len; $i < $nb_decimal; $i++) { $string .= '0'; } } else { $string = number_format($number, $nb_decimal, ',', ' '); } return $string; } var_dump(numericToStringDecimal(1000)); var_dump(number_format(1000, 2, ',', ' ')); var_dump(numericToStringDecimal(1000.5432543)); var_dump(number_format(1000.5432543, 2, ',', ' ')); var_dump(numericToStringDecimal(432143214321.5434325431)); var_dump(number_format(432143214321.5434325431, 2, ',', ' ')); var_dump(numericToStringDecimal(-43214321423.4343214123)); var_dump(number_format(-43214321423.4343214123, 2, ',', ' ')); var_dump(numericToStringDecimal(-43214321423e10)); var_dump(number_format(-43214321423e10, 2, ',', ' '));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/GSZq4
function name:  (null)
number of ops:  76
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   INIT_FCALL                                               'var_dump'
          1        INIT_FCALL                                               'numerictostringdecimal'
          2        SEND_VAL                                                 1000
          3        DO_FCALL                                      0  $0      
          4        SEND_VAR                                                 $0
          5        DO_ICALL                                                 
   24     6        INIT_FCALL                                               'var_dump'
          7        INIT_FCALL                                               'number_format'
          8        SEND_VAL                                                 1000
          9        SEND_VAL                                                 2
         10        SEND_VAL                                                 '%2C'
         11        SEND_VAL                                                 '+'
         12        DO_ICALL                                         $2      
         13        SEND_VAR                                                 $2
         14        DO_ICALL                                                 
   25    15        INIT_FCALL                                               'var_dump'
         16        INIT_FCALL                                               'numerictostringdecimal'
         17        SEND_VAL                                                 1000.54
         18        DO_FCALL                                      0  $4      
         19        SEND_VAR                                                 $4
         20        DO_ICALL                                                 
   26    21        INIT_FCALL                                               'var_dump'
         22        INIT_FCALL                                               'number_format'
         23        SEND_VAL                                                 1000.54
         24        SEND_VAL                                                 2
         25        SEND_VAL                                                 '%2C'
         26        SEND_VAL                                                 '+'
         27        DO_ICALL                                         $6      
         28        SEND_VAR                                                 $6
         29        DO_ICALL                                                 
   27    30        INIT_FCALL                                               'var_dump'
         31        INIT_FCALL                                               'numerictostringdecimal'
         32        SEND_VAL                                                 4.32143e+11
         33        DO_FCALL                                      0  $8      
         34        SEND_VAR                                                 $8
         35        DO_ICALL                                                 
   28    36        INIT_FCALL                                               'var_dump'
         37        INIT_FCALL                                               'number_format'
         38        SEND_VAL                                                 4.32143e+11
         39        SEND_VAL                                                 2
         40        SEND_VAL                                                 '%2C'
         41        SEND_VAL                                                 '+'
         42        DO_ICALL                                         $10     
         43        SEND_VAR                                                 $10
         44        DO_ICALL                                                 
   29    45        INIT_FCALL                                               'var_dump'
         46        INIT_FCALL                                               'numerictostringdecimal'
         47        SEND_VAL                                                 -4.32143e+10
         48        DO_FCALL                                      0  $12     
         49        SEND_VAR                                                 $12
         50        DO_ICALL                                                 
   30    51        INIT_FCALL                                               'var_dump'
         52        INIT_FCALL                                               'number_format'
         53        SEND_VAL                                                 -4.32143e+10
         54        SEND_VAL                                                 2
         55        SEND_VAL                                                 '%2C'
         56        SEND_VAL                                                 '+'
         57        DO_ICALL                                         $14     
         58        SEND_VAR                                                 $14
         59        DO_ICALL                                                 
   31    60        INIT_FCALL                                               'var_dump'
         61        INIT_FCALL                                               'numerictostringdecimal'
         62        SEND_VAL                                                 -4.32143e+20
         63        DO_FCALL                                      0  $16     
         64        SEND_VAR                                                 $16
         65        DO_ICALL                                                 
   32    66        INIT_FCALL                                               'var_dump'
         67        INIT_FCALL                                               'number_format'
         68        SEND_VAL                                                 -4.32143e+20
         69        SEND_VAL                                                 2
         70        SEND_VAL                                                 '%2C'
         71        SEND_VAL                                                 '+'
         72        DO_ICALL                                         $18     
         73        SEND_VAR                                                 $18
         74        DO_ICALL                                                 
         75      > RETURN                                                   1

Function numerictostringdecimal:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 13
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 17, Position 2 = 38
Branch analysis from position: 17
2 jumps found. (Code = 43) Position 1 = 30, Position 2 = 31
Branch analysis from position: 30
1 jumps found. (Code = 42) Position 1 = 35
Branch analysis from position: 35
2 jumps found. (Code = 44) Position 1 = 37, Position 2 = 33
Branch analysis from position: 37
1 jumps found. (Code = 42) Position 1 = 45
Branch analysis from position: 45
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 33
2 jumps found. (Code = 44) Position 1 = 37, Position 2 = 33
Branch analysis from position: 37
Branch analysis from position: 33
Branch analysis from position: 31
Branch analysis from position: 38
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
2 jumps found. (Code = 43) Position 1 = 17, Position 2 = 38
Branch analysis from position: 17
Branch analysis from position: 38
filename:       /in/GSZq4
function name:  numericToStringDecimal
number of ops:  47
compiled vars:  !0 = $number, !1 = $nb_decimal, !2 = $int_part, !3 = $dec_part, !4 = $dec_len, !5 = $string, !6 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      2
    5     2        CAST                                          4  ~7      !0
          3        ASSIGN                                                   !2, ~7
    6     4        SUB                                              ~9      !0, !2
          5        ASSIGN                                                   !3, ~9
    7     6        STRLEN                                           ~11     !3
          7        SUB                                              ~12     ~11, 2
          8        ASSIGN                                                   !4, ~12
    8     9        IS_SMALLER                                               0, !4
         10      > JMPZ                                                     ~14, ->13
         11    >   QM_ASSIGN                                        ~15     !4
         12      > JMP                                                      ->14
         13    >   QM_ASSIGN                                        ~15     0
         14    >   ASSIGN                                                   !4, ~15
    9    15        IS_SMALLER                                               !4, !1
         16      > JMPZ                                                     ~17, ->38
   10    17    >   INIT_FCALL                                               'number_format'
         18        SEND_VAR                                                 !0
         19        SEND_VAR                                                 !4
         20        SEND_VAL                                                 '%2C'
         21        SEND_VAL                                                 '+'
         22        DO_ICALL                                         $18     
         23        ASSIGN                                                   !5, $18
   11    24        INIT_FCALL                                               'str_contains'
         25        SEND_VAR                                                 !5
         26        SEND_VAL                                                 '%2C'
         27        DO_ICALL                                         $20     
         28        TYPE_CHECK                                    4          $20
         29      > JMPZ                                                     ~21, ->31
   12    30    >   ASSIGN_OP                                     8          !5, '%2C'
   14    31    >   ASSIGN                                                   !6, !4
         32      > JMP                                                      ->35
   15    33    >   ASSIGN_OP                                     8          !5, '0'
   14    34        PRE_INC                                                  !6
         35    >   IS_SMALLER                                               !6, !1
         36      > JMPNZ                                                    ~26, ->33
    9    37    > > JMP                                                      ->45
   18    38    >   INIT_FCALL                                               'number_format'
         39        SEND_VAR                                                 !0
         40        SEND_VAR                                                 !1
         41        SEND_VAL                                                 '%2C'
         42        SEND_VAL                                                 '+'
         43        DO_ICALL                                         $27     
         44        ASSIGN                                                   !5, $27
   20    45    > > RETURN                                                   !5
   21    46*     > RETURN                                                   null

End of function numerictostringdecimal

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
147.85 ms | 992 KiB | 21 Q