Add Sales Tax

Easy · rating 900 · math

Read a price p in cents and a sales-tax rate r as a whole percentage. Print the total the customer pays, in cents, with the tax rounded down to the nearest cent.

Constraints: 0 ≤ p ≤ 109, 0 ≤ r ≤ 100

Editorial

Add Sales Tax adds a whole-percent tax to a price, rounding the tax down. Compute the tax as price · r / 100 with integer division and add it back — all in integer cents to avoid floating-point drift.

print(price + price * r // 100)

Complexity

Time: O(1). Space: O(1).

Open Add Sales Tax in Code Arena →