Excel 2011中的FormatCurrency

时间:2014-07-24 00:40:08

标签: excel-vba excel-2011 vba excel

下面是我使用Excel 2010从Youtube教程中提取的一些代码。当我尝试在Excel 2011上为Mac运行时,货币输出都是整数。 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

1 个答案:

答案 0 :(得分:0)

代码在Windows 7 PC上的Excel 2010中运行良好。尝试使用VBE中的立即窗口并查看一些debug.print语句,看看发生了什么。

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

以为你应该知道它确实有效。