本文介绍了仅用两个小数舍入一个双精度值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好

我需要将一个双精度值四舍五入到两个小数位.

我需要做的.

例如

x = 7.3256

我需要在x = 7.33
中转换x
如何在C#代码中做到这一点.

在此先感谢

Hello Everybody

I need to round a double value with two decimal places.

What I need to do that.

for example

x=7.3256

I need convert x in x=7.33

How I can do that in c# code.

Thanks in advance

推荐答案

x = Math.Round(x, 2);


System.Console.WriteLine("{0:G3}", myDoublePrecisionNumber);




or

string output =
   string.Format("{0:G3}", myDoublePrecisionNumber);



要获取更多帮助,请键入string.Format,在格式"上按F1并阅读Microsoft帮助-所有您需要的信息.
除非确实需要,否则不要弄乱取整.



For further help, type string.Format, press F1 on Format and read Microsoft help -- all you need.
Don''t mess with rounding unless it is really needed.


这篇关于仅用两个小数舍入一个双精度值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-29 09:18
查看更多