문제

I'm using QBFC to generate invoices in a Quickbooks integrating app. I'm getting an exception thrown for lineItem.Amount.SetValue(val as Double) 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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top