Method Deck / finance

Discount and markup

Applies a percentage discount or a percentage markup to a price and returns the new price and the dollar change.

Published for review. The Founder is checking every card himself; anything he strikes comes down the same hour.

Try it

Inputs

Outputs

Steps

  1. Convert the percent to a decimal: p = percent / 100.
  2. amount_change = price * p.
  3. If mode is discount, new_price = price - amount_change; if mode is markup, new_price = price + amount_change.
  4. Round new_price and amount_change to 2 decimals (money to cents).

Constants

None.

Sources

Worked example and test vectors

NameInputsAnswer
worked example{"price":80,"percent":25,"mode":"discount"}$60.00
test vector: markup{"price":150,"percent":40,"mode":"markup"}$210.00

Published card