PHP转换为整数返回错误的值 [英] PHP cast to integer returns wrong value

查看:235
本文介绍了PHP转换为整数返回错误的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

看看这个朋友,告诉我我不疯了...

Have a look at this my friend and tell me I'm not crazy...

echo (int) (9.45 * 100); // gives 944
echo (int) 945; // gives 945

我不明白为什么第一条指令会返回944!这是一个已知的php问题?

I don't understand why the first instruction would return 944!???? Is this a known php issue? help is appreciated as always!

推荐答案

根据PHP文档( http://php.net/manual/en/language.types.integer.php

When converting from float to integer, the number will be rounded towards zero. 

这就是为什么你会得到944。

That's why you are getting 944.

这篇关于PHP转换为整数返回错误的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆