PHP中的圆形表示科学记数法而不是全数字

时间:2020-12-08 22:34:31

I'm trying to do an echo of a variable containing 1400000. so there is written: echo round(1400000); this gives 1,4E+6 instead of the full number. Anybody an idea on how to display it fully?

我试图做一个包含1400000的变量的回声。所以有写:echo round(1400000);这给出了1,4E + 6而不是全数。有人知道如何完全展示它吗?

3 个解决方案

#1


It seems that round was the problem. I changed it with number_format() and this does the job just fine. Thanks Aron and Paul for the answers.

似乎圆是问题所在。我用number_format()更改了它,这就完成了工作。感谢Aron和Paul的答案。

#2


Related to your question, I also came across this comment on the PHP website.

与您的问题相关,我也在PHP网站上看到了这个评论。

PHP switches from the standard decimal notation to exponential notation for certain "special" floats. You can see a partial list of such "special" values with this:

对于某些“特殊”浮点数,PHP从标准十进制表示法切换到指数表示法。您可以使用以下方法查看此类“特殊”值的部分列表:

for( $tmp = 0, $i = 0; $i < 100; $i++ ) 
{
    $tmp += 100000;
    echo round($tmp),"\n"; 
} 

So, if you add two floats, end up with a "special" value, e.g. 1.2E+6, then put that value unmodified into an update query to store the value in a decimal column, say, you will likely get a failed transaction, since the database will see "1.2E+6" as varchar data, not decimal. Likewise, you will likely get an XSD validation error if you put the value into xml.

因此,如果添加两个浮点数,最后会得到一个“特殊”值,例如1.2E + 6,然后将该值未修改为更新查询以将值存储在十进制列中,例如,您可能会收到失败的事务,因为数据库将“1.2E + 6”视为varchar数据,而不是十进制。同样,如果将值放入xml,您可能会收到XSD验证错误。

I have to be honest: this is one of the strangest things I have seen in any language in over 20 years of coding, and it is a colossal pain to work around.

我必须说实话:这是我在20多年的编码中用任何语言看到的最奇怪的事情之一,这是一个巨大的痛苦。

It seems there has not been a "real" fix yet, but judging from the comments in the bug report Paul Dixon referered to earlier, his solution seems to work.

似乎还没有一个“真正的”解决方案,但从保罗迪克森之前提到的错误报告中的评论来看,他的解决方案似乎有效。

#3


Possibly related to this bug report, so you could try

可能与此错误报告有关,因此您可以尝试

printf("%d", $myvar);

#1


It seems that round was the problem. I changed it with number_format() and this does the job just fine. Thanks Aron and Paul for the answers.

似乎圆是问题所在。我用number_format()更改了它,这就完成了工作。感谢Aron和Paul的答案。

#2


Related to your question, I also came across this comment on the PHP website.

与您的问题相关,我也在PHP网站上看到了这个评论。

PHP switches from the standard decimal notation to exponential notation for certain "special" floats. You can see a partial list of such "special" values with this:

对于某些“特殊”浮点数,PHP从标准十进制表示法切换到指数表示法。您可以使用以下方法查看此类“特殊”值的部分列表:

for( $tmp = 0, $i = 0; $i < 100; $i++ ) 
{
    $tmp += 100000;
    echo round($tmp),"\n"; 
} 

So, if you add two floats, end up with a "special" value, e.g. 1.2E+6, then put that value unmodified into an update query to store the value in a decimal column, say, you will likely get a failed transaction, since the database will see "1.2E+6" as varchar data, not decimal. Likewise, you will likely get an XSD validation error if you put the value into xml.

因此,如果添加两个浮点数,最后会得到一个“特殊”值,例如1.2E + 6,然后将该值未修改为更新查询以将值存储在十进制列中,例如,您可能会收到失败的事务,因为数据库将“1.2E + 6”视为varchar数据,而不是十进制。同样,如果将值放入xml,您可能会收到XSD验证错误。

I have to be honest: this is one of the strangest things I have seen in any language in over 20 years of coding, and it is a colossal pain to work around.

我必须说实话:这是我在20多年的编码中用任何语言看到的最奇怪的事情之一,这是一个巨大的痛苦。

It seems there has not been a "real" fix yet, but judging from the comments in the bug report Paul Dixon referered to earlier, his solution seems to work.

似乎还没有一个“真正的”解决方案,但从保罗迪克森之前提到的错误报告中的评论来看,他的解决方案似乎有效。

#3


Possibly related to this bug report, so you could try

可能与此错误报告有关,因此您可以尝试

printf("%d", $myvar);