开发者

Can I prevent this operation from returning an answer in Scientific Notation?

I've got a fairly simple formula, although it involves a large-ish number, which is basically this:

$one = 13开发者_运维知识库00391053;   
$two = 0.768;

// $millitime = 1.30039116114E+12    
$millitime = ($one+$two)*1000;

I understand this is the technically correct answer but I'm expecting to get 1300391053768. The goal of this is to get the time in milliseconds. I could combine the two and remove the decimal although that feels a bit odd.

Is there a way to get this to store 'properly' ?

[ as as side note, it seems not all installations handle this the same. My local PHP install (v5.3 on MacOS) returns the sci notation, but I run the identical code writecodeonline.com and get what I'm expecting/wanting. ]


try using php's number_format()

so:

$one = 1300391053;   
$two = 0.768;
$millitime = number_format(($one+$two)*1000);


What is "storing properly"? If you use print_r($millitime); you'll get 1300391053768. The value is stored "properly", the only question is how you want the output formatted. You could use number_format or sprintf for it.

echo sprintf('%.0f', $millitime) . PHP_EOL; // 1300391053768
echo sprintf('%e',   $millitime) . PHP_EOL; // 1.300391e+12

echo number_format($millitime, 0, '.', '') . PHP_EOL; // 1300391053768
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜