进行除法有困难 [英] Having trouble performing division

查看:78
本文介绍了进行除法有困难的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试"计算涉及除法的表达式时,我没有得到正确的答案.例如:双数= 5/9; Console.WriteLine(number.ToString());,结果为0!这里发生了什么?为什么我没有得到.55555 ...?

When I "attempt" to calculate a expression that involves division I''m not getting the correct answer. Example: double number = 5/9; Console.WriteLine(number.ToString());, the result is 0! What''s going on here? Why am I not getting .55555...?

推荐答案

您需要做的是:

what you would need to do is:

double number1 = 5.0/9.0;
double number2 = (double)5/(double)9;
double number3 = 5D/9D;


谢谢.那行得通,但考虑到我最初声明数字"为双精度,为什么我不知道为什么必须强制转换为双精度?您能跟我澄清一下吗?
thanks. that worked but I don''t understand why I had to type cast to double considering that I initially declared "number" a double? would you please clarify this with me?


谢谢!我即将检查您发送给我的MSDN链接.再次感谢您!
thank you! I''m about to check out the MSDN link you sent me. Again thank you!


这篇关于进行除法有困难的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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