首页 > 解决方案 > 计算贴现率

问题描述

我有商品的原价和折扣价。我目前有一些代码,但它不能正常工作。

例如:打折前商品的价格为 853.2 美元。折扣价为 349 美元。那是 59% 的折扣,但我的代码显示错误的数字。

Dim a1 As String = (Val(pre-discounted_price) - Val(discount_price) * 100 / Val(discount_price)).ToString

Dim a2 As Integer = (853.2 - 349) * 100 / 349

标签: vb.net

解决方案


计算您需要折扣多少才能达到新价格的公式是:

100 * (originalprice - newprice) / originalprice

100 * (852.3 - 349) / 852.3 = 59 (0 decimal places)

Checking:
852.3 - (852.3 * 0.59) = 349 (approx)

您的代码出错了,因为您除以 newprice


推荐阅读