C# - Math.Round [英] C# - Math.Round

查看:159
本文介绍了C# - Math.Round的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想了解如何舍入到与C#最近的十分之一的地位。举例来说,我有一个值是double类型。这种双当前设置为10.75。不过,我需要圆,然后截断一切都会过去的十分之一的地位。在这种情况下,我正在找的10.8的值。我如何四舍五入到十分之一位置在C#?



感谢您!


解决方案

  Math.Round(yourNumber,1)

第二个参数是小数舍入到的数目。在你的情况,你要1个小数位作为最终结果。


I am trying to understand how to round to the nearest tenths position with C#. For instance, I have a value that is of type double. This double is currently set to 10.75. However, I need to round and then truncate everything past the tenths position. In this case, I am seeking a value of 10.8. How do I round to the tenths position in C#?

Thank you!

解决方案

Math.Round(yourNumber, 1)

The second parameter is number of decimal places to round to. In your case you want 1 decimal place as an end result.

这篇关于C# - Math.Round的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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