How come I get a rounded number when I multiply doubles?? [modified]
-
ely_bob wrote:
dbRecipeTotal = (double)(((double)(RI.Quantity / dbRecipeTotalQuantity)) * ((double)(InvItem.Price / 100))); this will make sure that you are always in the precision your looking for, indepentant of whether you use a lower precision numeral type.
ely_bob, your solution still doesn't work because (InvItem.Price / 100) will be 24, so ((double)(InvItem.Price / 100)) will be 24.0 It needs to be ((double)InvItem.Price / 100). I didn't cast the 100 to double because when one of the arguments to operator/ is a double, the other one is automatically cast (I think).
double Quantity = 28.88887; double dbRecipeTotalQuantity = 28.88887; int Price = 2425; double dbRecipeTotal = (Quantity / dbRecipeTotalQuantity) * (Price / 100.0);
-
How come I get a rounded number when I multiply and assign value to a double??
dbRecipeTotal = (RI.Quantity / dbRecipeTotalQuantity) * (InvItem.Price / 100);
double dbRecipeTotal = 0.0;
RI.Quantity is = 28.88887
dbRecipeTotalQuantity is = 28.88887
InvItem.Price is = 2425I get dbRecipeTotal = 24.0 in quickview it should be 24.25 Any help is appreaciated
modified on Wednesday, July 28, 2010 9:44 AM