Igor Glazunov
Мастер
(1980)
15 лет назад
AFAIK такой функции в VBA нет, а Round округляет по математическим правилам, т. е. Round(8.431, 2) = 8.43
Лови:
Function SmartRound(expression As Double, Optional numdecimalplaces As Integer = 0) As Double
If expression > Round(expression, numdecimalplaces) Then
SmartRound = Round(expression, numdecimalplaces) + 1.0 / (10 ^ numdecimalplaces)
Else
SmartRound = Round(expression, numdecimalplaces)
End If
End Function
Wowa Cherkesov
Просветленный
(24048)
15 лет назад
функция округления
Public Function Rd(ByVal Number As Variant, NumDigits As Long) As Double
Dim dblPower As Double
Dim varTemp As Variant
Dim intSgn As Integer
If Not IsNumeric(Number) Then
' Raise an error indicating that you've supplied an invalid parameter.
err.Raise 5
End If
dblPower = 10 ^ NumDigits
' Is this a negative number, or not?
' intSgn will contain -1, 0, or 1.
intSgn = Sgn(Number)
Number = Abs(Number)
' Do the major calculation.
varTemp = CDec(Number) * dblPower + 0.5
' Finish the calculation.
Rd = intSgn * Int(varTemp) / dblPower
End Function
1.575
1.585
8.431
Нужно округлить до чисел:
1.58
1.59
8.44