CodingHero
CodingHero

Reputation: 683

convert csv number format to real number

when parsing a CSV file, how would I transform the scientific notation numbers into real numbers?

For example in a column I have : 4,41431E+13 I think it's real value is : 44143100000000

I have tried using number_format but it doesn't convert.

Thanks

Upvotes: 0

Views: 1548

Answers (2)

fvu
fvu

Reputation: 32953

The main issue is that the scientific notation shown in your sample is using a comma as decimal separator, so you first have to switch your locale to a locale that uses a comma (I use french in the example)

<?php
// switch the locale to one using , as decimal separator
setlocale(LC_NUMERIC, 'fr_FR');
// intermediate step via float as intval doesn't seem to like the comma
$big_float = floatval("4,41431E+13");
// and finally to integer
$big_integer = intval($big_float);

Now $big_integer will correctly contain the integer value 44143100000000

Upvotes: 3

Chris
Chris

Reputation: 4728

It's too late. Excel has already messed up the formatting. If you view the CSV in Notepad you'll see that this is the case.

Upvotes: -2

Related Questions