mardi 30 juin 2015

SQlite Calculation with same Values different Results

My Database contains this Values

  1. ROW: productName = Product 1, purchasePrice = 5099 , tax = 16, price = 10099
  2. ROW: productName = Product 1, purchasePrice = 5099 , tax = 16, price = 10099
  3. ROW: productName = Product 1, purchasePrice = 5099 , tax = 16, price = 10099
  4. ROW: productName = Product 1, purchasePrice = 5099 , tax = 16, price = 10099

  5. ROW: productName = Product 2, purchasePrice = 5099 , tax = 19, price = 10099

  6. ROW: productName = Product 2, purchasePrice = 5099 , tax = 19, price = 10099
  7. ROW: productName = Product 2, purchasePrice = 5099 , tax = 19, price = 10099

My Calculation for the Total Profit is this

SUM( price- ( price * tax/100.0  + purchasePrice)) as Profit

Result as Profit = 22780.210000000006

My Calculation for the Profit of every Product is this

SUM(price- (price*TAX/100.0 + purchasePrice)) as Profit GROUP BY productName

Result as Profit for Product 1 = 13536,6

Result as Profit for Product 2 = 9243,57

Total 22780,17

I have to round this Values and divide them by /100.0 because I've read that it is better to not store the values with floating points in Sqlite.

I do the rounding and /100.0 like this

Round for Total with the Result of = 227.8

ROUND((SUM( price- ( price * tax/100.0  + purchasePrice)))/100 ,2) as Profit

Round for every Product

ROUND((SUM( price- ( price * tax/100.0  + purchasePrice)))/100 ,2) as Profit

Product 1 result = 135,37

Product 2 result = 92,44

Total 227,81 but the Round for Total gives me the Result of = 227.8

Any ideas?

Aucun commentaire:

Enregistrer un commentaire