1

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

Jonathan
  • 3,464
  • 9
  • 46
  • 54
  • What is `amount` equal to in your example? Is it by any chance negative or out of some sort of bounds? – Blindy Mar 21 '10 at 22:28
  • 1
    Can you give us some sample data? What does the debugger tell you the value of "amount" is prior to the call to SetValue() ? – OJ. Mar 21 '10 at 22:29
  • Are you sure you're supposed to supply doubles? Perhaps this function requires decimals? Financial programs often work with decimals rather than doubles. – David Rutten Mar 21 '10 at 22:41

1 Answers1

2

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

Jonathan
  • 3,464
  • 9
  • 46
  • 54