简体   繁体   English

在c#中获取折扣值的百分比

[英]Get the percentage of the discount value in c#

In my applicattion i want to find how much in percent is the discount, I have the price of an item then when i give a new price and find the Subtraction I want to know how much is that in percent, example:在我的应用程序中,我想找到折扣的百分比,我有一个商品的价格,然后当我给出一个新价格并找到减法时,我想知道这个百分比是多少,例如:

decimal realPrice = 1800;
decimal newPrice = 1700;
decimal difference = realPrice - newPrice; // = 100
decimal discountPercent = ????;

How many percent is this diffence as a discount in percent from the realprice.这种差异是实际价格的百分比折扣。 Thank you in advance.先感谢您。

You should divide difference by realPrice and then multiply it by 100 to get percentages您应该将差异除以 realPrice,然后乘以 100 以获得百分比

decimal discountPercent = difference / realPrice * 100;

It should give you 5.(5)%它应该给你5.(5)%

See this working example请参阅此工作示例

decimal discountPercent = (difference / realPrice) * 100;
Console.WriteLine("Discount Percentage : {0}%",discountPercent.ToString("#.##"));

Little maths for explanation:数学解释:

decimal discountPercent = difference / realPrice * 100;

Though this is not a programming question, but rather math question for middle school.虽然这不是编程问题,而是中学数学问题。 :D :D

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM