如何围捕值C#为最接近的整数? [英] How to round up value C# to the nearest integer?
本文介绍了如何围捕值C#为最接近的整数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想圆了双为int。
例如,
double a=0.4, b=0.5;
我想他们两个更改为整数。
I want to change them both to integer.
让
int aa=0, bb=1;
AA
是 A
和 BB
是 b
。
任何公式来做到这一点?
Any formula to do that?
推荐答案
使用 Math.Ceiling
围捕
Math.Ceiling(0.5); // 1
使用 Math.Round
只是轮
Math.Round(0.5, MidpointRounding.AwayFromZero); // 1
和 Math.Floor
到本轮下跌
And Math.Floor
to round down
Math.Floor(0.5); // 0
这篇关于如何围捕值C#为最接近的整数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文