2

I fetch the csv data using file_get_contents() and explode to make an array

i got array

my code

<?php

    $csvcontent = file_get_contents($url);
    $csv_array = explode($lineseparator,$csvcontent); 
    $csv_array = array_filter($csv_array);

?>

I got array

 Array ( [0] => 2018-06-03,4477651688.19,163280,1.30288e+11,7632.09,4851760000.0,2037.5,15.3074038,531463,4.30694957398e+12,285966,246.271822195,1.356e-05,
         [1] => 2018-06-04,7925996820.24,209733,1.31847e+11,7722.53,4993170000.0,2287.5,20.71075272,702904,4.30694957398e+12,341314,310.568030875,1.373e-05,
         [2] => 2018-06-05,5821973644.02,212726,1.28081e+11,7500.9,4961740000.0,2187.5,18.52827963,655694,4.41559334167e+12,348466,305.3316354,1.531e-05
 )

How to change the scientic notation to decimal in php array

original number in csv is 0.00001356 . whilw i get using file_get_contents() . i got 1.356e-05. whil i use (float) $num or ($num + 0) it gives 1.356E-05. i need full number 0.00001356

Sammu Sundar
  • 556
  • 3
  • 9
  • 24

1 Answers1

0

First, you need to split the string and get the scientific number. Then you can convert.

PHP is dynamically typed. Try subtracting zero from the value. It'll convert the data type for you.

$val = '1.30288e+11';
$result = $val - 0;

echo "String: $val Number: $result";

You'll get the output

String: 1.30288e+11 Number: 130288000000
Fawzan
  • 4,738
  • 8
  • 41
  • 85
  • still not working Array ( [0] => 2018-06-03 [1] => 4477651688.19 [2] => 163280 [3] => 130288000000 [4] => 7632.09 [5] => 4851760000 [6] => 2037.5 [7] => 15.3074038 [8] => 531463 [9] => 4306949573980 [10] => 285966 [11] => 246.271822195 [12] => 1.356E-5 ) – Sammu Sundar Jun 06 '18 at 14:03
  • I use the same way you prefer. But "1.356e-05" change to "1.356E-05". not decimal value – Sammu Sundar Jun 06 '18 at 14:06
  • for($j=0;$j 0) { //~ $linearray[$j] = (string) $linearray[$j]; $linearray[$j] = ($linearray[$j] + 0); } } print_r($linearray); exit; using like this but not work – Sammu Sundar Jun 06 '18 at 14:15