使用Math.Round [英] Working with Math.Round
本文介绍了使用Math.Round的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Hi Geeks,
只是一个小疑问,
结果= 210900
Hi Geeks,
Just a small doubt,
result=210900
double value = Convert.ToDouble(result / 10000);
value=21.0
I need to get 21.09
如何获得这个?
谢谢
How to get this?
Thanks
推荐答案
1.当两个操作数都是整数时结果将被计算为整数(因此没有任何小数),然后最终结果将被转换为double。
2.解决方案是使用变量类型double
然后你可以使用Math.Round()
来获得你希望的下一个十进制数例如:
1.When both operands are integer the results will be computed as integer (so without any decimals), then the final result will be converted to double.
2.The solution is to use variable of typedouble
and then you could useMath.Round()
in order to get as many decimal you wanted like in the next example:
double value = Math.Round(result / 10000.0, 2);
这种方式
This way
int result = 210900;
double value = result / 10000.0;
访问这里...
valuue = Math.Round(转换.ToDouble(结果/ 10000)),2);
C#Math.Round(double,Int32)麻烦
或
< a href =http://msdn.microsoft.com/en-us/library/system.math.round%28v=vs.110%29.aspx?cs-save-lang=1&cs-lang=csharp#代码片断-11\" > http://msdn.microsoft.com/en-us/library/system.math.round%28v=vs.110%29.aspx?cs-save-lang=1&cs-lang = csharp#code-snippet-11 [ ^ ]
visit here...
valuue =Math.Round(Convert.ToDouble(result/10000)),2);
C# Math.Round(double,Int32) Troubles
or
http://msdn.microsoft.com/en-us/library/system.math.round%28v=vs.110%29.aspx?cs-save-lang=1&cs-lang=csharp#code-snippet-11[^]
这篇关于使用Math.Round的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文