在C#中向上或向下取整数值 [英] Rounding values up or down in C#

查看:993
本文介绍了在C#中向上或向下取整数值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个游戏这给在比赛的最后一分,但问题是,这个分数是有时小数点(如87.124563563566)后的数字有很多的数字。我怎么会去四舍五入向上或向下的价值,这样我可以有类似87.12?

I've created a game which gives a score at the end of the game, but the problem is that this score is sometimes a number with a lot of digits after the decimal point (like 87.124563563566). How would I go about rounding up or down the value so that I could have something like 87.12?

谢谢!

推荐答案

请尝试使用 Math.Round 。它的各种重载允许你指定你想要多少个数字,你也希望它的轮数过来的。

Try using Math.Round. Its various overloads allow you to specify how many digits you want and also which way you want it to round the number.

这篇关于在C#中向上或向下取整数值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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