Calculate a Discount
Problem statement
Given a nonnegative monetary amount amountCents and a percentage discount discountBasisPoints, calculate the discount amount in whole cents.
One basis point is 0.01%, so 10000 basis points represents 100%. Return floor(amountCents * discountBasisPoints / 10000).
Return the savings, rather than the remaining price. Round down once after multiplying; no eligibility, stacking, or stateful rules apply.
Function
calculateDiscount(amountCents: long, discountBasisPoints: int) → longExamples
Example 1
amountCents = 1000discountBasisPoints = 1500return = 1501500 basis points is 15%. The discount is 1000 * 1500 / 10000 = 150 cents.
Example 2
amountCents = 101discountBasisPoints = 3333return = 33The exact savings is 33.6633 cents. Rounding down once gives 33 cents.
Example 3
amountCents = 1000000000000discountBasisPoints = 10000return = 1000000000000A 100% discount equals the original amount. The product 10000000000000000 fits signed 64-bit arithmetic.
Constraints
0 <= amountCents <= 1000000000000.0 <= discountBasisPoints <= 10000.- Inputs are integers. Use signed 64-bit arithmetic for monetary values and intermediate products.