Search code examples
phpcsvexport-to-csv

I have imported csv into table using php but facing in problem?


I am facing this problem in excel file the value is 1.93E+11 and It is not converted into 193000000000 when I import the csv to MYSQL table. It's value remain the same as 1.93E+11

How can I do it to convert it my code is

  if ($_FILES["file"]["size"] > 0) {

    $file = fopen($fileName, "r");

    while (($column = fgetcsv($file, 58000, ",")) !== FALSE) {
            $sqlInsert = "INSERT into excel ()
               values ('" . $column[0] . "','" . $column[1] . "')";
        $result = mysqli_query($conn, $sqlInsert);

        if (! empty($result)) {
            $type = "success";
            $message = "CSV Data Imported into the Database";

Solution

  • You can typecast it to a float:

    $value = (float) $column[1];
    

    To be sure that you actually have a floating point number you can try checking like this

    if (is_numeric($column[1]) && !is_int($column[1])) {
        $value = (float) $column[1];
    }