C#是由自身四舍五入师 [英] C# is rounding down divisions by itself

查看:212
本文介绍了C#是由自身四舍五入师的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我做在C#中一个部门,它automaticaly几轮下来。见这个例子:

When I make a division in C#, it automaticaly rounds down. See this example:

double i;
i = 200 / 3;
Messagebox.Show(i.ToString());

这表明我含66一个消息。三分之二百实际上是66.66666〜但是。

This shows me a messagebox containing "66". 200 / 3 is actually 66.66666~ however.

有没有一种方法可以让我避免这种四舍五入下来并保存了一些像66.6666667?

Is there a way I can avoid this rounding down and keep a number like 66.6666667?

推荐答案

I =3分之200正在执行整数除法。

尝试之一:

I =(双)3分之200

I = 200.0 / 3

I = 200D / 3

声明的常量作为双之一将导致所使用的双除法运算符。

Declaring one of the constants as a double will cause the double division operator to be used.

这篇关于C#是由自身四舍五入师的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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