我需要将值舍入到最接近的2.5的倍数.
例如:
6 – > 7.5
7.6 – > 10
等等
这似乎是最好的方法吗?
Function RoundToIncrement(ByVal originalNumber As Decimal,ByVal increment As Decimal) As Decimal Dim num = Math.Round(originalNumber / increment,MidpointRounding.AwayFromZero) * increment If originalNumber Mod increment <> 0 And num < originalNumber Then num += increment End If Return num End Function
将数字除以2.5,向上舍入到最接近的整数,然后将结果乘以2.5.
原文链接:https://www.f2er.com/vb/255419.html你很亲密
Function RoundToIncrement(ByVal orignialNumber As Decimal,ByVal increment As Decimal) As Decimal Return Math.Ceiling( orignialNumber / increment ) * increment End Function
Math.Ceiling将始终向上舍入非整数,因此您不需要进行后期调整.