In the real world the discount on products you purchase is quite in开发者_如何学运维teresting. For example a seller offers a discount on his products in the following way:
- On buying one quantity there will be no discount
- On buying 2 he offers 10% discount
- On buying 4 and 5 disount will be 20%
- On 6 and onward 22%
What is the best way to accomplish this in an eCommerce application?
Take a ceiling function of the exponent or approximation thereof. For example Discount = MaxDiscount * (1 - (N-1)/N), where N is number of items. for 1 item discount is 0, for 2 items discount is 1/2 of the max, for large number of item it will approach MaxDiscount. Use ceiling function to you want discount to be integer number.
精彩评论