如何将双精度值转换为.NET中选定数量的小数位? [英] How to round a double value to a selected number of decimals in .NET?

查看:188
本文介绍了如何将双精度值转换为.NET中选定数量的小数位?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用加速度传感器来计算当前的加速度,并返回双倍值。

I use an acceleration sensor to calculate the current accelerations and it returns the double value.

然而,我想将当前加速度与值9.8进行比较。在这之前,我必须舍弃从传感器收到的值,所以问题是:如何在.NET中将双精度值转换为所选数字的小数位数?

However I would like to compare the current acceleration with value 9.8. Before doing that i have to round the value received from the sensor so the question is: How to round a double value to a selected number of decimals in .NET?

推荐答案

Math.Round(number,precision)

Math.Round(number, precision)

http://msdn.microsoft.com/en-us/library/zy06z30k.aspx

这篇关于如何将双精度值转换为.NET中选定数量的小数位?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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