下面是我使用 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