You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
67 lines
2.0 KiB
C#
67 lines
2.0 KiB
C#
namespace RoBot.Core
|
|
{
|
|
public class Utils
|
|
{
|
|
public static string FormatNumberToChineseUnit(decimal number)
|
|
{
|
|
if (number >= 100000000) // 亿
|
|
{
|
|
decimal value = number / 100000000.0M;
|
|
return $"{value:0.#}亿";
|
|
}
|
|
else if (number >= 10000) // 万
|
|
{
|
|
decimal value = number / 10000.0M;
|
|
return $"{value:0.#}万";
|
|
}
|
|
else
|
|
{
|
|
return number.ToString();
|
|
}
|
|
}
|
|
|
|
public static decimal ParseChineseNumber(string chineseNumber)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(chineseNumber))return 0;
|
|
|
|
chineseNumber = chineseNumber.Trim();
|
|
|
|
decimal multiplier = 1;
|
|
if (chineseNumber.Contains("亿"))
|
|
multiplier = 100000000;
|
|
else if (chineseNumber.Contains("万"))
|
|
multiplier = 10000;
|
|
var numberPart = chineseNumber.Replace("亿", "").Replace("万", "");
|
|
if (!decimal.TryParse(numberPart, out decimal value)) return 0;
|
|
|
|
return value * multiplier;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 计算手续费
|
|
/// </summary>
|
|
/// <param name="amount"></param>
|
|
/// <returns></returns>
|
|
public static decimal CalculateFee(decimal amount)
|
|
{
|
|
decimal rate = 0;
|
|
|
|
if (amount < 500_0000) // 0 ~ 499w
|
|
rate = 0.05m; // 5%
|
|
else if (amount < 1000_0000) // 500 ~ 999w
|
|
rate = 0.10m; // 10%
|
|
else if (amount < 1500_0000) // 1000 ~ 1499w
|
|
rate = 0.15m; // 15%
|
|
else if (amount < 2000_0000) // 1500 ~ 1999w
|
|
rate = 0.20m; // 20%
|
|
else // 2000w以上
|
|
rate = 0.30m; // 30%
|
|
|
|
return amount * rate;
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|