How to round a double value to a selected number of decimals in .NET?

自闭症网瘾萝莉.ら 提交于 2019-12-24 07:35:24

问题


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

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?


回答1:


Math.Round(number, precision)

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




回答2:


Math.Round - i.e.

double val = Math.Round(current, 1); // 1dp


来源:https://stackoverflow.com/questions/693493/how-to-round-a-double-value-to-a-selected-number-of-decimals-in-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!