This commit is contained in:
2026-02-12 22:15:15 +08:00
parent 47a5cff08b
commit 502c6efedc
58 changed files with 2114 additions and 708 deletions

View File

@@ -0,0 +1,36 @@
using System;
namespace NBF
{
public static class GameUtil
{
/// <summary>
/// 格式化数字显示大于等于10000显示N万保留1位小数点整数1万、2万不要小数点
/// </summary>
/// <param name="number">要格式化的数字</param>
/// <returns>格式化后的字符串</returns>
public static string FormatNumber(this int number)
{
if (number < 10000)
{
return number.ToString(); // 小于10000直接显示
}
// 转换为万为单位
double valueInTenThousand = number / 10000.0;
// 判断是否为整数万
if (Math.Abs(valueInTenThousand - Math.Floor(valueInTenThousand)) < 0.00001) // 处理浮点数精度
{
// 整数万,不显示小数点
return $"{(int)valueInTenThousand}万";
}
// 非整数万向下取整并保留1位小数
double flooredValue = Math.Floor(valueInTenThousand * 10) / 10;
// 处理浮点数精度确保只显示1位小数
return $"{flooredValue:F1}万";
}
}
}