1

I wrote a function to add a comma to every 8 zero of my number

I need to store value in PHP variable or array, but it's saved as "1.0E+30"

here is my PHP code:

function SplitHex($number) {
$number_split = str_split($number,1);
$number_split_revers = array_reverse($number_split);
$i = 0;
foreach ($number_split_revers as $key => $value ) {
    if ( $value == 0) {
        $i++;
        if ( $i == 8 ) {
        $number_split_revers[$key] = str_replace(0,",0",$value);
        $i=0;
        }
    }

}
    $final = '';
    $number_final = array_reverse($number_split_revers);
    foreach ($number_final as $value ) {
        $final .= $value;   
    }

//$final = strval(implode("",$number_final));

return $final;

and I call the function :

$test[2] = SplitHex(1000000000000000000000000000000);
var_dump ($test);
print_r ($test);

the output of echo print_r var_dump are all same :

1.0E+30

but it must be 1000000,00000000,00000000,00000000

I searched a lot but couldn't find the right solution for this problem

user3325376
  • 198
  • 1
  • 15
  • you may need to take a look at this http://stackoverflow.com/questions/8647125/using-long-int-in-php – hassan Feb 21 '17 at 13:31
  • See http://stackoverflow.com/questions/4427020/is-there-a-biginteger-class-in-php – Nerea Feb 21 '17 at 13:35

1 Answers1

1

FYI,

if the number if too long, it can not fit into 32 integer format in php, so it store it in float.

So you can not see that integer value if it exceed PHP_INT_MAX size.

But this is an alternative for this,

$test[2] = number_format(SplitHex(1000000000000000000000000000000),0,null,'');
var_dump ($test);
print_r ($test);

Give it a try, it should work.

Rahul
  • 17,231
  • 7
  • 35
  • 54
  • it's not working, the output is `1000000000000000019884624838656` but it should be `1000000,00000000,00000000,00000000` – user3325376 Feb 21 '17 at 14:08