0

下面是我使用 Excel 2010 从 Youtube 教程中提取的一些代码。当我尝试在 Mac 的 Excel 2011 上运行它时,货币输出都是整数。FormatCurrency() 在此版本的 Excel 中的工作方式是否有所不同?还是我刚刚(再次)搞砸了什么?谢谢你的帮助。

最佳,托尼·利马

Option Explicit
' Tony Lima, July 23, 2014

Const SCOOPPRICE As Double = 0.75
Const TIPPERCENT As Double = 0.15

' ****************************************
' Ice cream store order and print receipt
' *****************************************

Private Sub btnOrder_Click()
    Dim numScoops As Integer
    Dim scoopCost As Double
    Dim tipAmount As Double
    Dim totalCost As Double

    '*** get the number of scoops ordered
    numScoops = CInt(txtScoops.Text)
    '*** calculate cost of ice cream and tip amount
    scoopCost = numScoops * SCOOPPRICE
    tipAmount = scoopCost * TIPPERCENT
    '*** add the two to get the total cost
    totalCost = scoopCost + tipAmount

    '*** print receipt
    lstReceipt.AddItem ("Thanks for your order!")
    lstReceipt.AddItem ("")
    lstReceipt.AddItem ("You ordered " & CStr(numScoops) & " scoops of ice cream")
    lstReceipt.AddItem ("Cost of ice cream " & FormatCurrency(scoopCost, 2))
    lstReceipt.AddItem ("Tip (thank you) " & FormatCurrency(tipAmount, 2))
    lstReceipt.AddItem ("Total cost " & FormatCurrency(totalCost, 2))

End Sub
4

1 回答 1

0

代码在 Windows 7 电脑上的 Excel 2010 中运行良好。尝试使用 VBE 中的即时窗口并在其中添加一些 debug.print 语句以查看发生了什么。

Debug.print FormatCurrency(scoopCost,2) for example...

只是想你应该知道它确实有效。

于 2014-07-24T16:57:33.217 回答