例如,我有一臺打折的電腦,這臺電腦的價格是 450 美元,有 10% 的折扣,我想知道它的真實價格,我想了解這超過 10% 和 10% 的錢。
Computer 10% off Price = 450$
Computer $10 off Price = 490$
$net_total = 450;
$discount_value = 10; < percent or amount
$gross_price = ?;
uj5u.com熱心網友回復:
好吧,讓我們解方程:
Computer 10% off Price = 450$
Computer $10 off Price = 490$
可以寫成(假設x計算機的初始價格)
x - x * 10 / 100 = 450 # initial price - x without 10 % from x - x * 10% / 100%
x - 10 = 490 # just 10$ off
或者
0.9 * x = 450
x = 500
最后
x = 450 / 0.9 = 500
x = 500
所以從這兩個等式我們得到初始計算機的價格是 500$
編輯:在一般情況下,
如果$discount_value代表百分比(即$discount_value = 10意味著10%折扣)那么
$gross_price = $net_total * 100.0 / (100.0 - $discount_value)
如果$discount_value代表錢(即$discount_value = 10表示10$折扣),則
$gross_price = $net_total $discount_value
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/343361.html
上一篇:陣列中的引數型別問題('float'、'constint')
下一篇:Sql查詢中的四舍五入數字整數
