TotalAmountAfterDiscount

TotalAmountAfterDiscount

本文介绍了如何在datagridview中计算时设置条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我有一个问题需要你的帮助。



问题:



我有datagridview有这样的5列



数量价格TotalAmount折扣TotalAmountAfterDiscount



表达式为:



TotalAmount =数量*价格

TotalAmountAfterDiscount = TotalAmount * Discount / 100(问题!!!)



如果Discount = 0%,表达式将出错。所以我想在这里设置条件如果Discount细胞的值等于0我们将有其他表达式TotalAmountAfterDiscount = TotalAmount



请帮我解决这个问题。非常感谢你



@note:我正在使用DataColumnName.Expression来计算和datagridview数据源绑定到由代码创建的临时表,因为我想要计算所有之后的值将所有数据插入数据库

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

推荐答案


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





因此,更改您的TotalAmountAfterDiscount计算,0%折扣将正常工作。



So change your TotalAmountAfterDiscount calculation, and 0% discount will work fine.


这篇关于如何在datagridview中计算时设置条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-26 19:29