我需要将值舍入到最接近的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
harpo.. 19
将数字除以2.5,向上舍入到最接近的整数,然后将结果乘以2.5.
你很亲密
Function RoundToIncrement(ByVal orignialNumber As Decimal, ByVal increment As Decimal) As Decimal Return Math.Ceiling( orignialNumber / increment ) * increment End Function
Math.Ceiling将始终向上舍入非整数,因此您不需要进行后期调整.
将数字除以2.5,向上舍入到最接近的整数,然后将结果乘以2.5.
你很亲密
Function RoundToIncrement(ByVal orignialNumber As Decimal, ByVal increment As Decimal) As Decimal Return Math.Ceiling( orignialNumber / increment ) * increment End Function
Math.Ceiling将始终向上舍入非整数,因此您不需要进行后期调整.
将数字除以2.5.舍入到最接近1.乘以2.5.
谨防累积错误,你们都已经准备好了.
-亚当