专用与计量认证的数据处理。
规则:1 保留小数点后两位有效数字(以小数点后,第一个非零数算起两位数字)
2 四舍六入五奇偶:“五奇偶”是指第三位有效数为5时,要看第二位的奇偶属性
奇数进,偶数舍
举例:11.00155 ----> 11.0016
11.00165 ----> 11.0016
11.135 ----> 11.14
11.500 ----> 11.50
11.550 ----> 11.55
11.56001 ----> 11.56 *只要有非零尾数,无论奇偶都要进位
----------------------------------
Public Function cmcrnd(anumber As Double) As Double
anumber = Int(anumber * 10 ^ 6) / 10 ^ 6
Dim a As Double
Dim a1, n As Byte
Dim t As String
n = 0
a = anumber
t = Mid(Trim(Str(FORMatNumber(a - Int(a), 4, , , vbUseDefault))), 2)
For a1 = 1 To 4
If Mid(t, a1, 1) <> "0" Then
Exit For
Else: n = n + 1
End If
Next
If Eval(Right(Str(Int(a * 1000 * 10 ^ n)), 1)) > 5 And Eval(Right(Str(Int(a * 100000)), 2)) > 0 Then
a = Int(a * 100 * 10 ^ n + 1) / (100 * 10 ^ n)
Else:
If Eval(Right(Str(Int(a * 1000 * 10 ^ n)), 1)) = 5 Then
If Eval(Right(Str(Int(a * 100 * 10 ^ n)), 1)) Mod 2 = 0 Then
a = Int(a * 100 * 10 ^ n) / (100 * 10 ^ n)
Else: a = Int(a * 100 * 10 ^ n + 1) / (100 * 10 ^ n)
End If
Else: a = Int(a * 100 * 10 ^ n) / (100 * 10 ^ n)
End If
End If
Select Case no
Case 1
a = FORMatNumber(a, 3)
Case 2
a = FORMatNumber(a, 4)
Case 3
a = FORMatNumber(a, 5)
End Select
cmcrnd = a
End Function
能告诉我这段代码错在那里吗
[此贴子已经被作者于2006-5-29 9:32:59编辑过]
|