ntan ntan - 6 months ago 10
PHP Question

Convert 9.78960040953E+12 to a string in PHP

I am using Excel Reader to parse an Excel document.
The file contains an ISBN (

978960040953
) and the reader returns
9.78960040953E+12
.

I have set the Excel column type to
text
, but no luck. I have also tried using
(string)
and
strval()
, but still no luck.

One option is to multiply the value so it becomes an integer, but ISBN and ISBN13 have different sizes.

Could anyone help me converting
9.78960040953E+12
to
978960040953
?

Answer

Use floatval and (string) typecasting. http://codepad.org/M87DDiXy

<?php

$a = "9.78960040953E+12";
$b = (string) floatval($a);
var_dump($b);

?>

Output:
string(13) "9789600409530"
Comments