开发者

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜