3v4l.org

run code in 300+ PHP versions simultaneously
<?php $tests = [ "7.2769482308e+01", "3.43E-6", "2.54E-14", "99.87E-2" ]; foreach($tests as $test){ echo $test, " => ", getFormattedDecimal($test),PHP_EOL; } function getFormattedDecimal($str){ $precision = explode("e", strtolower($str)); $precision = substr($precision[1], 1); // remove + and - operators return sprintf("%.".$precision."f", $str); }
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
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
filename:       /in/3hoZu
function name:  (null)
number of ops:  13
compiled vars:  !0 = $tests, !1 = $test
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   10     1      > FE_RESET_R                                       $3      !0, ->11
          2    > > FE_FETCH_R                                               $3, !1, ->11
   11     3    >   ECHO                                                     !1
          4        ECHO                                                     '+%3D%3E+'
          5        INIT_FCALL_BY_NAME                                       'getFormattedDecimal'
          6        SEND_VAR_EX                                              !1
          7        DO_FCALL                                      0  $4      
          8        ECHO                                                     $4
          9        ECHO                                                     '%0A'
   10    10      > JMP                                                      ->2
         11    >   FE_FREE                                                  $3
   18    12      > RETURN                                                   1

Function getformatteddecimal:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/3hoZu
function name:  getFormattedDecimal
number of ops:  23
compiled vars:  !0 = $str, !1 = $precision
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   RECV                                             !0      
   15     1        INIT_FCALL                                               'explode'
          2        SEND_VAL                                                 'e'
          3        INIT_FCALL                                               'strtolower'
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                         $2      
          6        SEND_VAR                                                 $2
          7        DO_ICALL                                         $3      
          8        ASSIGN                                                   !1, $3
   16     9        INIT_FCALL                                               'substr'
         10        FETCH_DIM_R                                      ~5      !1, 1
         11        SEND_VAL                                                 ~5
         12        SEND_VAL                                                 1
         13        DO_ICALL                                         $6      
         14        ASSIGN                                                   !1, $6
   17    15        INIT_FCALL                                               'sprintf'
         16        CONCAT                                           ~8      '%25.', !1
         17        CONCAT                                           ~9      ~8, 'f'
         18        SEND_VAL                                                 ~9
         19        SEND_VAR                                                 !0
         20        DO_ICALL                                         $10     
         21      > RETURN                                                   $10
   18    22*     > RETURN                                                   null

End of function getformatteddecimal

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
138.91 ms | 1006 KiB | 17 Q