Files
agentd-livetest/src/Prices/PriceCalculator.cs
agentd df12cee1ef Preisrechner: Rappenrundung im Backend und Rabatt-Rechner im Web
agentd task d23b198e9bef4e0c99f52c532c317f70
2026-08-04 23:17:03 +00:00

22 lines
789 B
C#

namespace Prices;
/// <summary>Turns a list price into what the customer actually pays.</summary>
public static class PriceCalculator
{
/// <summary>Applies a percentage discount to a price, e.g. 25 for a quarter off.</summary>
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;
}
}