我有双号,我想总是近似它。
例如:1.2324 - > 1 1.898 - > 2
我怎么能用C#做到这一点?
答案 0 :(得分:3)
使用Math.Round()
。
double d1 = Math.Round(1.2324); //d1 is 1
double d2 = Math.Round(1.898); //d2 is 2
答案 1 :(得分:0)
答案 2 :(得分:0)
Math.Round(double)
可以解决问题。如果要在小数点后面使用可变小数位数,可以使用Math.Round(double, int)
描述此内容的API为here。