1

I just successfully uploaded and read through on a csv file using PHP Codigniter. What I want to do now is to format the numbers for example:

6.06861E+11

to

606861000000

before inserting it to the database. How should I do this in PHP? Thank you.

4
  • Do you see that number in excel or where? Your column is set to a bigint as well? 606861000000 will exceed int. Commented Jul 28, 2015 at 2:16
  • 1
    is the number stored as "6.06861E+11" or just displayed as "6.06861E+11" Commented Jul 28, 2015 at 2:17
  • in the csv file the number is already formatted to "6.06861E+11" Commented Jul 28, 2015 at 2:28
  • 1
    How did it get to that format? I'd fix the issue at the point of creation. Commented Jul 28, 2015 at 2:29

2 Answers 2

1

PHP understands scientific notation, you just need to let it know that you want it formatted as a number. You can accomplish this by subtracting zero from it like so.

<?php
$x = '6.06861E+11';
echo $x - 0;
?>  

Displays -> 606861000000

Sign up to request clarification or add additional context in comments.

1 Comment

No Problem. Good luck with your project!
0

Use the following function to convert from exponential to the right number format:

     function easy_number_format($number, $dec_point, $thousands_sep)
       {
       $number = rtrim(sprintf('%f', $number), "0");
       if (fmod($nummer, 1) != 0) {                      
       $array_int_dec = explode('.', $number);
       } else { 
       $array_int_dec= array(strlen($nummer), 0);
       }
       (strlen($array_int_dec[1]) < 2) ? ($decimals = 2) : ($decimals =                             strlen($array_int_dec[1]));
      return number_format($number, $decimals, $dec_point,                  $thousands_sep);
        } 

1 Comment

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.