mirror of
https://github.com/GeWuYou/GFramework.git
synced 2026-03-22 10:34:30 +08:00
- 在LocalizationManager中注册内置格式化器包括条件、复数和紧凑数值格式化器
- 实现CompactNumberLocalizationFormatter支持{value:compact}格式化语法
- 添加数值显示扩展方法ToDisplayString和ToCompactString
- 实现NumericDisplayFormatter和NumericSuffixFormatRule数值格式化核心逻辑
- 添加数值格式化选项配置包括小数位数、四舍五入策略等参数
- 为紧凑数值格式化功能添加完整的单元测试覆盖各种数值类型和边界情况
30 lines
924 B
C#
30 lines
924 B
C#
using System.Numerics;
|
|
using GFramework.Core.Abstractions.Utility.Numeric;
|
|
using GFramework.Core.Utility.Numeric;
|
|
|
|
namespace GFramework.Core.Extensions;
|
|
|
|
/// <summary>
|
|
/// 数值显示扩展方法。
|
|
/// </summary>
|
|
public static class NumericDisplayExtensions
|
|
{
|
|
/// <summary>
|
|
/// 按指定选项将数值格式化为展示字符串。
|
|
/// </summary>
|
|
public static string ToDisplayString<T>(this T value, NumericFormatOptions? options = null) where T : INumber<T>
|
|
{
|
|
return NumericDisplay.Format(value, options);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 使用默认紧凑风格将数值格式化为展示字符串。
|
|
/// </summary>
|
|
public static string ToCompactString<T>(
|
|
this T value,
|
|
int maxDecimalPlaces = 1,
|
|
IFormatProvider? formatProvider = null) where T : INumber<T>
|
|
{
|
|
return NumericDisplay.FormatCompact(value, maxDecimalPlaces, formatProvider);
|
|
}
|
|
} |