English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
所有分類

我想要求值, 而且可以求到小數第三位並且可以四捨五入,我應該怎麼做

2006-10-04 18:39:29 · 3 個解答 · 發問者 ? 1 in 電腦與網際網路 程式設計

3 個解答

以下提供參考...
Private Sub Form_Activate()
Dim dot As Single, num As Single, z As Single, out As Single
num = Val(InputBox("請輸入數值"))
z = Fix(num) '整數部份
dot = num - z '小數部份
dot = Round(dot, 4) '只保留小數點後4位
If Mid(dot, Len(Str(dot)), 1) >= 5 Then dot = Round(dot + 0.0005, 3) Else dot = Round(dot, 3)
out = z + dot
Print out
End Sub

2006-10-04 19:51:41 · answer #1 · answered by 天使 4 · 0 0

HerVal=4捨5入的質
b=小數到第幾位

Function ttt(HerVal As Variant, b As Integer)


HerVal = HerVal * (10 ^ b) + 0.5
ttt = Fix(HerVal) / (10 ^ b)

End Function

Private Sub Command1_Click()
Debug.Print ttt(10.1235, 3)
'答案會是 10.124
End Sub

2006-10-09 19:23:57 · answer #2 · answered by 小小涵 3 · 0 0

N = Val(InputBox("請輸入數值"))Print Val(Format(N,"0.000"))

2006-10-05 09:29:56 · answer #3 · answered by W.J.S. 7 · 0 0

fedest.com, questions and answers