feat:第一次提交
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
namespace NapCatRobotClient.Core
|
||||
{
|
||||
public class Utils
|
||||
{
|
||||
/// <summary>
|
||||
/// 格式化数字为中文单位
|
||||
/// </summary>
|
||||
/// <param name="number"></param>
|
||||
/// <returns></returns>
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 解析中文数字
|
||||
/// </summary>
|
||||
/// <param name="chineseNumber"></param>
|
||||
/// <returns></returns>
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user