I've got a fairly simple formula, although it involves a large-ish number, which is basically this:
$one = 1300391053;
$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 The value is stored "properly", the only question is how you want the output formatted. You could use number_format or sprintf for it.print_r($millitime); you'll get 1300391053768.
echo sprintf('%.0f', $millitime) . PHP_EOL; // 1300391053768
echo sprintf('%e', $millitime) . PHP_EOL; // 1.300391e+12
echo number_format($millitime, 0, '.', '') . PHP_EOL; // 1300391053768
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With