VBA格式用户窗体数字输出

我有一个电子表格/用户界面的组合,需要用户input来计算产品定价/百分比税收和平方英尺,考虑到在用户表单的一个文本框中输出地板的总成本。

我的用户表单正在计算一切正常,但我想弄清楚如何格式化输出框,以便它只显示值超过小数两位数字(即$ 1.00)。 目前,最多显示小数点后四位数字(如“总面积”,“税额”和“最终价格”文本框中所示)。

在这里输入图像说明

我的用户表单代码如下(我忽略了一些与打开和closures用户表单有关的非相关部分,但是与它的function有关的所有内容都在那里):

Public Sub SumTool() Dim A, B, C, D, E, F As Double Dim x As Double Dim finalSum As Double Dim addUp As Double Dim BeforePercent As Double Dim Prcnt As Double Dim percentALT As Double Dim percentSum As Double Dim i As Integer addUp = 0 finalSum = 0 BeforePercent = 0 x = 0 i = 0 'These are all area measurements A = 280 B = 118 C = 96 D = 243 E = 38 F = 83 Do While i < 1 'These are checks to see if checkboxes in the userform are True/False and 'correspond to the area measurements above If LR.Value = True Then x = x + A Else x = x End If If BR1.Value = True Then x = x + B Else x = x End If If BR2.Value = True Then x = x + C Else x = x End If If KT.Value = True Then x = x + D Else x = x End If If BA.Value = True Then x = x + E Else x = x End If If HALL.Value = True Then x = x + F Else x = x End If i = i + 1 Loop 'I have different calculations because the user has the option of 'whether they want to include tax or not. If they do not (first option) 'no special conversions have to take place. If they do, the program has to 'take the entry and convert it from 5 or 10 to 0.05 or 0.10 and then carry 'forward with the rest of the operations If Me.Y.Value = False Then Prcnt = 0 addUp = x finalSum = addUp * Me.ProductPrice.Value Me.FinalResultsBox.Value = finalSum Me.SqFtBox.Value = addUp Me.TaxAmountValue.Value = 0 Else Prcnt = Me.SalesTaxNumber.Value addUp = x percentALT = Prcnt * 0.01 BeforePercent = addUp * Me.ProductPrice.Value percentSum = percentALT * BeforePercent finalSum = BeforePercent + percentSum Me.FinalResultsBox.Value = finalSum Me.SqFtBox.Value = addUp Me.TaxAmountValue.Value = percentSum End If End Sub 

你可以尝试这样的事情…

 Me.FinalResultsBox.Value = Format(finalSum, "$0.00")