C#-四舍五入到最接近的整数
问题描述:
我有一个正在计算一些数字的C#应用程序.我需要四舍五入.
I have a C# app that is calculating some numbers. I need to round down.
var increment = 1.25;
var result = 50.45 - 23.70; // equals 26.75
int interval = difference / increment; // result is 21.4. However, I just want 21
I have to get the interval
to an int
. At the same time, I cannot just use Convert.ToInt32
because of its rounding behavior. I always want the lowest whole number. However, I'm not sure how.
答
只需尝试一下.
int interval = Convert.ToInt32(Math.Floor(different/increment));