Click here to Skip to main content
15,904,817 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello everyone , I have a question need your help .

Question :

I have a datagridview have 5 columns like this

Quantity Prices TotalAmount Discount TotalAmountAfterDiscount

The expression is :

TotalAmount = Quantity * Prices
TotalAmountAfterDiscount = TotalAmount * Discount/100 ( Problem here !!!)

If Discount = 0% the expression will go wrong . So i want set condition here if values of Discount cells equal 0 we will have other expression TotalAmountAfterDiscount = TotalAmount

Please help me solve this problem . Thanks you a lot

@note : I'm using DataColumnName.Expression to calculate and datagridview datasource is bound to temp table which created by code because i want to calculate all values after that insert all of it to database
Posted

Looks to me like your formula for the total amount after discount is incorrect. What you're calculating with TotalAmount * Discount/100 is the amount of the discount, not the total amount after discount, which would be total amount - discount amount, right? Fix your formula and you fix your problem.
 
Share this answer
 
You do realize that that expression won't work anyway?
Price = 100
Quantity = 10
TotalAmount = P * Q = 1000
Discount = 25%
TotalAmountAfterDiscount = (P * Q) * D / 100 = 1000 * 25 / 100 = 250

What you actually want is:
Price = 100
Quantity = 10
TotalAmount = P * Q = 1000
Discount = 25%
TotalAmountAfterDiscount = (P * Q) - ((P * Q) * D / 100) = 1000 - (1000 * 25 / 100) = 1000 - 250 = 750


So change your TotalAmountAfterDiscount calculation, and 0% discount will work fine.
 
Share this answer
 
Comments
Anhduc Mai 21-Jun-13 11:59am    
Thanks for your help . feel so stupid now :( . It so easy ^^
OriginalGriff 21-Jun-13 12:05pm    
:laugh:
We all make mistakes!
(And it's a damn sight easier to spot other peoples... ;) )

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900