Different kinds of doubles in vb.net?
I'm using QBFC to generate invoices in a Quickbooks integrating app. I'm getting an exception thrown for lineItem.Amount.SetValue(val as Do开发者_运维问答uble) when I try to enter a programmatically generated double.
The following does not work:
lineItem = invoice.ORInvoiceLineAddList.Append.InvoiceLineAdd
Dim amount as Double
amount = summary.dailySold * summary.dailyRate
loggingTxtBox.AppendText("Amount is " & amount & vbNewLine)
lineItem.Amount.SetValue(amount)
The exception I receive is System.Runtime.InteropServices.COMException (0x80040305): Invalid Amount format. at Interop.QBFC8.IQBAmountType.SetValue(Double val)
The following works:
lineItem.Amount.SetValue(20.3)
Any suggestions? Is .NET interpretting a hard-coded double differently than a programmatically calculated one?
Thanks- Jonathan
Found it.
Printing out "amount" showed 21.3
However, using the debugger "amount" actually contained 21.299999999997. SetValue only accepts doubles with two decimal points.
This did the trick:
amount = CDbl(amount.ToString("F"))
Is there a more efficient way to round a double to two decimal places?
Thanks
Jonathan
精彩评论