Backend for the Teso project written in 2022
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
1.6 KiB

3 months ago
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Teso_API.Models
{
public class CouponRateCalculator
{
public static int GetRate(double discount)
{
if (discount < 100)
{
string discounted = $"{discount:F1}";
string first = discounted.Substring(0, discounted.IndexOf("."));
string last = discounted.Substring(discounted.IndexOf(".") + 1);
int firstNumber = int.Parse(first);
int lastNumber = int.Parse(last);
if (discount < 0.51)
{
return 0;
}
else if (discount < 2)
{
return 1;
}
else if (firstNumber < lastNumber)
{
return lastNumber;
}
else if (firstNumber > lastNumber)
{
return firstNumber;
}
else
{
return firstNumber;
}
}
else if (discount < 1000)
{
double result = discount % 100;
if (result == 0)
{
return 100;
}
else
{
return (int)Math.Ceiling(result);
}
}
else
{
return 100;
}
}
}
}