Skip to content
Advertisement

Format 15-digit number PHP

I’m trying to format the following number from a json url.

1835488750000000

to

18,354,887

Here is my code

$json_url = $Api;
$json = file_get_contents($json_url);

$data = json_decode($json, true);

$total = $data['value'];    

echo number_format(trim($total , 0));

It returns

1.83549E+15

I’m tying to format the value of totalbc from the api url

Thank you

Advertisement

Answer

You could divide it by 1E8 and use number_format:

number_format(1835488750000000/1E8);
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement