namespace Prices;
/// Turns a list price into what the customer actually pays.
public static class PriceCalculator
{
/// Applies a percentage discount to a price, e.g. 25 for a quarter off.
public static decimal ApplyDiscount(decimal price, decimal discountPercent)
{
if (price < 0)
{
throw new ArgumentOutOfRangeException(nameof(price), "A price cannot be negative.");
}
if (discountPercent is < 0 or > 100)
{
throw new ArgumentOutOfRangeException(nameof(discountPercent), "A discount is between 0 and 100 percent.");
}
var raw = price * (100 - discountPercent) / 100;
return Math.Round(raw / 0.05m, MidpointRounding.AwayFromZero) * 0.05m;
}
}