0

我目前使用简单的 msgbox calc 来返回计算值。如何限制答案 msgbox 中返回值中显示的小数位数。

这是脚本!

Sub CalcmsgboxHect()
    On Error Resume Next
    num = InputBox("Please Enter The Number Of Acres You Would Like To Calculate Into Hectares ")
    MsgBox num * 0.404686 & " Is the Number Of Hectares."
End Sub
4

1 回答 1

1

干得好。这将应用具有两位小数和千位分隔符的格式:

编辑:如果 num = 0,则包裹在 IF 中以跳过。

Sub CalcmsgboxHect()
Dim num As Double

num = Application.InputBox(prompt:="Please Enter The Number Of Acres You Would Like To Calculate Into Hectares ", Type:=1)
If num <> 0 Then
    MsgBox Format(num * 0.404686, "#,##0.00") & " Is the Number Of Hectares."
End If
End Sub

作为奖励,我宣布numDouble(尽管你的鲁莽绰号)。另外,我使用Application.Inputbox了 ,它允许您指定和输入类型。输入类型1意味着用户必须输入数字。这可能会让你摆脱这On Error Resume Next条线。

于 2013-05-22T02:50:58.303 回答