i am running this code in vb.net:
Dim sub_total as Double = 0
Dim amount As Double = 0
Dim customer_total As Double = 0
SQL = "SELECT invoice, product, cost, price, commission FROM billing_salesman_commission WHERE invoice = '" & reader2.GetString(0) & "';"
myCommand3.Connection = conn3
myCommand3.CommandText = SQL
reader3 = myCommand3.ExecuteReader
While reader3.Read
'profit = sell price - cost price
amount = reader3.GetString(3) - reader3.GetString(2)
'commission amount = profit * (commission % / 100)
amount = amount * (reader3.GetString(4) / 100)
'update the customer total
customer_total = customer_total + amount
'insert excel data
'MsgBox("insert excel")
End While
reader3.Close()
sub_total = sub_total + customer_total
from the query above that creates a loop, i have calculated all of the figures manually on a calculator.
there are 2 unique values for invoice
and each one totals the following:
- 5.44
- 9.41
which should equal 14.85
however sub_total is returning 14.84