Discount and return new value - M-Farag/micro-algorithms GitHub Wiki

Inputs:
  • Algorithm expects two floats as params:[amount, discount]
  • The amount param is the original price you want to apply the discount on.
  • The discount param is the float representation of the percentage you want to apply to the original amount.
Outputs:
  • Afloat number representing the new amount value after applying/deducting the discount.
Idea:
  • If you want to deduct 3% of 100$, The new amount should be 97% of the 100$.
  • The algorithm math in calculating the remaining percentage out of the original amount.
  • So: 100 * ( (100/100) - (3/100) ) which can be simplified to be: ( 100 * ( 1 - (3/100) ) )