聪明的 if 语句和大数字
此代码
{if 10111060108552250999929 == 10111060108552250999924}
true1
{/if}
{if 10111060108552250999929 == 20111060108552250999924}
true2
{/if}
输出“true1”,但两个语句都不成立。
Smarty 是否有比较整数的最大大小?如果是的话,为什么看起来有点“模糊”呢?
希望我只是犯了一个愚蠢的错误。
This code
{if 10111060108552250999929 == 10111060108552250999924}
true1
{/if}
{if 10111060108552250999929 == 20111060108552250999924}
true2
{/if}
outputs 'true1' but neither statement is true.
Does Smarty have a maximum size for comparing integers? If so, why does it appear to be a bit "fuzzy"?
Hopefully I've just made a stupid mistake.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这是 PHP 整数类型溢出的问题。它根据操作系统位 (32/64) 的不同而变化。
请参阅:
It's the problem with PHP's integer type overflow. It varies based on the OS bit (32/64).
Please see:
由于这些数字对于常规
int
类型来说太大,Smarty 会(根据 自动转换 PHP 确实)将它们与float
进行比较,导致精度损失。Since these numbers are too large for the regular
int
type, Smarty will (as per the automatic conversion PHP does) be comparing them asfloat
s, resulting in loss of precision.您应该考虑使用 BCMath 为 smarty 编写一个比较插件,因此大数字将是正确处理。
You should consider writing a comparsion plugin for smarty usin BCMath, therefore big numbers will be handled correctly.
我可能是错的,但你的第二个 if 语句总是错误的......因为这些数字不一样......
I might be wrong, but your second if statement is always false...as those numbers are not the same..