Ответить на сообщение
Вернуться к теме
Вы отвечаете на сообщение:
ник: Дядя Федор
Public Function Round( _ ByVal Number As Variant, NumDigits As Long, _ Optional UseBankersRounding As Boolean = False) As Double 'ЕЩЕ ОДНА ВСПОМОГАТЕЛЬНАЯ ФУНКЦИЯ , округляет указанное число, до указанной точности 'Here s the version I recently wrote that solves that last issue. I've 'sent this in to Advisor to post as an errata. I think this will work 'now... -- Ken 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 ' Do the major calculation. varTemp = CDec(Number) * dblPower + 0.5 ' Now round to nearest even, if necessary. If UseBankersRounding Then ' Is this a negative number, or not? ' intSgn will contain -1, 0, or 1. intSgn = Sgn(Number) varTemp = Abs(varTemp) If Int(varTemp) = varTemp Then If varTemp Mod 2 = 1 Then ' If working with a negative number, ' add 1. If working with a ' positive number, subtract one. ' That's what "- intSgn" will do. varTemp = _ intSgn * (varTemp - intSgn) End If End If End If ' Finish the calculation. Round = Int(varTemp) / dblPower End Function
Ваше имя:
Пароль:
Сообщение:
Прикрепить:
Для вставки смайлов в текст щелкните по значку.