开发者

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 IS开发者_Go百科BN and ISBN13 have different sizes.

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


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"


You could use the function strval() to convert the value to a string. Have a look at the manual.

Then you could easily manipulate the string to get the exact value you want using the string functions (e.g. str_replace and substr()).

$str = strval($number);
$str = str_replace('.', '', $str);
$str = substr($str, 0, 12);

var_dump($str); //Output: string(12) "978960040953"


$str = number_format($number, 0, '.', '');


In the excel sheet use the special format (with zip code) example.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜