Dynamic Discount on Products

走远了吗. 提交于 2021-02-19 06:21:25

问题


In the real world the discount on products you purchase is quite interesting. 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?


回答1:


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.



来源:https://stackoverflow.com/questions/5576340/dynamic-discount-on-products

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!