帮助C部门# [英] Help with division C#
本文介绍了帮助C部门#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
双x = 74/120;
预计:0.6166666 ......但结果为0.为什么?
double x = 74/120;
Expected: 0.6166666... But the result is 0. Why ?
推荐答案
74和120是整数,所以除法将返回一个整数然后将其转换为double。
尝试74.0 / 120.0
74 and 120 are integers so the division will return an integer and then convert it to double.
Try 74.0 / 120.0
你也可以使用cast
像这样,
You can also usecast
like this,
double number3 = (double)number1/(double)number2;
欲了解更多信息,请参阅此处,
http://www.dotnetperls.com/divide [ ^ ]
施放整数加倍..你会得到预期的结果
cast the integers to double ..you will get the expected result
这篇关于帮助C部门#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文