4舍6入5看右,5后有数进上去,尾数为0向左看,左数奇进偶舍弃
答案:2 悬赏:0 手机版
解决时间 2021-08-01 23:51
- 提问者网友:温旧梦泪无声
- 2021-08-01 04:26
求数值修约的程序,实现如题,如果函数写的好的,可以申请悬赏分值!先谢谢了!java实现的代码更好,记住我要的是代码!
最佳答案
- 五星知识达人网友:廢物販賣機
- 2021-08-01 05:44
Public Function sRound(ByVal Data As Double, ByVal Number As Integer) As Double
Dim Temp As Double
If Number < 0 Then sRound = 0: Exit Function
Temp = Data - Int(Data)
If Len(Str(Temp)) <= Number + 2 Then
sRound = Data
Else
Dim Temp1, Temp2 As Double
Temp1 = Data * (10 ^ Number) - Int(Data * (10 ^ Number))
If Temp1 < 0.5 Then
Temp1 = 0
ElseIf Temp1 = 0.5 Then
Temp2 = Int(Data * (10 ^ Number))
If Temp2 Mod 2 = 0 Then
Temp1 = 0
Else
Temp1 = 1
End If
Else
Temp1 = 1
End If
sRound = (Int(Data * (10 ^ Number)) + Temp1) / (10 ^ Number)
End If
End Function
Dim Temp As Double
If Number < 0 Then sRound = 0: Exit Function
Temp = Data - Int(Data)
If Len(Str(Temp)) <= Number + 2 Then
sRound = Data
Else
Dim Temp1, Temp2 As Double
Temp1 = Data * (10 ^ Number) - Int(Data * (10 ^ Number))
If Temp1 < 0.5 Then
Temp1 = 0
ElseIf Temp1 = 0.5 Then
Temp2 = Int(Data * (10 ^ Number))
If Temp2 Mod 2 = 0 Then
Temp1 = 0
Else
Temp1 = 1
End If
Else
Temp1 = 1
End If
sRound = (Int(Data * (10 ^ Number)) + Temp1) / (10 ^ Number)
End If
End Function
全部回答
- 1楼网友:西岸风
- 2021-08-01 06:13
不明白那段简洁的描述
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯