Can I prevent this operation from being answered in Scientific Notation?

I have a fairly simple formula, although it includes a large number, which is basically this:

$one = 1300391053;   
$two = 0.768;

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

I understand that this is technically the correct answer, but I expect to receive it 1300391053768. The purpose of this is to get time in milliseconds. I could combine the two and remove the decimal number, although this is a bit strange.

Is there a way to make this store "correctly"?

[as a side note, it seems that not all installations handle this the same way. My local PHP installation (v5.3 on MacOS) returns sci notation, but I run the identical writecodeonline.com code and get what I expect / want. ]

+3
source share
3 answers

Use this to print it in a standard entry,

$big_integer = 1202400000;  
$formatted_int = number_format($big_integer, 0, '.', ''); 
echo $formatted_int; //outputs 1202400000 as expected 

$sample_float = (float)100000 //float; 
$formatted_float = number_format($sample_float, 2, '.', ''); 
echo $formatted_float; //outputs 100000.00 as expected

,

+5

php number_format()

:

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

What is the "right to store"? If you use print_r($millitime);, you will receive 1300391053768. The value is saved "correctly", the only question is how you want the format to be formatted. You can use number_format or sprintf for this.

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

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

All Articles