是"长×= 1/2英寸等于1或0,为什么? [英] Is "long x = 1/2" equal to 1 or 0, and why?

查看:144
本文介绍了是"长×= 1/2英寸等于1或0,为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有这样的:

long x = 1/2;

不应该这样被四舍五入至1?当我打印在屏幕上,它说0。

shouldn't this be rounded up to 1? When I print it on the screen it say 0.

推荐答案

它做整数除法,这一切截断到小数点的右侧。

It's doing integer division, which truncates everything to the right of the decimal point.

这篇关于是"长×= 1/2英寸等于1或0,为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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