浮动到 UNIX 纪元

发布于 2024-10-08 21:07:02 字数 197 浏览 0 评论 0原文

我正在从一个 JSON 数据库中提取数据,该数据库存储了 unix 纪元中的时间,但由于某种原因,当我提取它们时,数字会浮动。这是我以前从未遇到过的事情。因此,基本上像 1293083730000 这样的数字显示为 1.293085408E+12 我需要将数字返回到纪元时间,以便我可以将其与当前时间进行比较。任何帮助都会很棒。

I am pulling data from an JSON database that is storing the time in unix epoch but for some reason the numbers are being floated when I'm pulling them out. This is something I've never had to deal with before. So basiclly a number like 1293083730000 is showing up as 1.293085408E+12 I need to get the number back to the epoch time so I can compare it to the current time. Any help would be great.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

明月松间行 2024-10-15 21:07:02

这是工程表示法,一种书写大数的便捷方法。该数字仍然是整数。

问题是 PHP 的内部类型太小,无法将数字表示为小数,请参见以下示例:

<?
$i = 1293083730000;
echo "\$i is $i\n\n";
echo sprintf("\$i is %d\n\n", $i);
echo sprintf("\$i is %e\n\n", $i);
?>

此输出:

$i is 1293083730000

$i is 298573904

$i is 1.293084e+12

您需要 64 位平台,或者将数字作为字符串或浮点值使用。有关更多详细信息,请参阅有关整数的 PHP 文档:

http://php.net/manual /en/language.types.integer.php

That's engineering notation, a convenient method of writing large numbers. The number is still an integer.

The problem is is that PHP's internal types are too small to represent the number as a decimal, see the following example:

<?
$i = 1293083730000;
echo "\$i is $i\n\n";
echo sprintf("\$i is %d\n\n", $i);
echo sprintf("\$i is %e\n\n", $i);
?>

This outputs:

$i is 1293083730000

$i is 298573904

$i is 1.293084e+12

You need either a 64-bit platform or work with the number as a string or floating point value. See the PHP documentation on Integers for more details:

http://php.net/manual/en/language.types.integer.php

人│生佛魔见 2024-10-15 21:07:02

php.ini配置文件中,有一个值' precision'

它只是定义了浮点数中将显示多少位数字。

更多信息请参见 PHP 手册

您可以提高精度值并重试。

In the php.ini configuration file, there is a value 'precision'.

It simply defines how many digits will be shown in a float number.

More informations in PHP manual

You can increase the precision value and try again.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文