namespace CommonUtil { /// /// 格式化扩展方法 /// public static partial class ExtendUtil { /// /// 获取格式化字符串 /// /// 数值 /// 空值显示的默认文本 /// string public static string Format(this int number, string defaultValue = "--") { return number == 0 ? defaultValue : number.ToString(); } /// /// 获取格式化字符串 /// /// 数值 /// 空值显示的默认文本 /// string public static string Format(this int? number, string defaultValue = "--") { return Format(SafeGetValue(number), defaultValue); } /// /// 获取格式化字符串 /// /// 数值 /// 空值显示的默认文本 /// string public static string Format(this decimal number, string defaultValue = "--") { return number == 0 ? defaultValue : string.Format("{0:0.##}", number); } /// /// 获取格式化字符串 /// /// 数值 /// 空值显示的默认文本 /// string public static string Format(this decimal? number, string defaultValue = "--") { return Format(SafeGetValue(number), defaultValue); } /// /// 获取格式化字符串 /// /// 数值 /// 空值显示的默认文本 /// string public static string Format(this double number, string defaultValue = "--") { return number == 0 ? defaultValue : string.Format("{0:0.##}", number); } /// /// 获取格式化字符串 /// /// 数值 /// 空值显示的默认文本 /// string public static string Format(this double? number, string defaultValue = "--") { return Format(SafeGetValue(number), defaultValue); } /// /// 获取格式化字符串,带¥ /// /// 数值 /// string public static string FormatRmb(this decimal number) { return number == 0 ? "¥0" : string.Format("{0:0.##}", number); } /// /// 获取格式化字符串,带¥ /// /// 数值 /// string public static string FormatRmb(this decimal? number) { return FormatRmb(SafeGetValue(number)); } /// /// 获取格式化字符串,带% /// /// /// string public static string FormatPercent(this decimal number) { return number == 0 ? string.Empty : string.Format("{0:0.##}%", number); } /// /// 获取格式化字符串,带% /// /// /// string public static string FormatPercent(this decimal? number) { return FormatPercent(SafeGetValue(number)); } /// /// 获取格式化字符串,带% /// /// /// string public static string FormatPercent(this double number) { return number == 0 ? string.Empty : string.Format("{0:0.##}%", number); } /// /// 获取格式化字符串,带% /// /// /// string public static string FormatPercent(this double? number) { return FormatPercent(SafeGetValue(number)); } } }