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.
43 lines
1.2 KiB
C#
43 lines
1.2 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;
|
|
}
|
|
|
|
|
|
}
|
|
}
|