vb.net - 计算贴现率
问题描述
我有商品的原价和折扣价。我目前有一些代码,但它不能正常工作。
例如:打折前商品的价格为 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
解决方案
计算您需要折扣多少才能达到新价格的公式是:
100 * (originalprice - newprice) / originalprice
100 * (852.3 - 349) / 852.3 = 59 (0 decimal places)
Checking:
852.3 - (852.3 * 0.59) = 349 (approx)
您的代码出错了,因为您除以 newprice
推荐阅读
- mysql - 数据库架构:当记录具有不同数量的属性(列)
- python - beautifulsoup select 方法返回回溯
- android - 是什么导致 Google Play 开发者控制台中出现此警告:“我们检测到您的应用正在使用旧版本的 Google Play 开发者 API”
- php - 为什么添加标题后无法获取 POSTFIELDS?
- react-native - 如何在本机反应中跨组件全局调用一种方法
- c# - 类型列表参数的正确命名约定
- c# - 将委托转换为 lambda?
- r - 具有两组 x 标签的 Ggplot 分组柱形图
- windows - 如何重命名子文件夹或 zip 文件中的文本文件
- ruby - 使用现有文件 url 更新 CarrierWave 对象