namespace NFine.Code { public static partial class Ext { /// /// 获取描述 /// /// 布尔值 public static string Description(this bool value) { return value ? "是" : "否"; } /// /// 获取描述 /// /// 布尔值 public static string Description(this bool? value) { return value == null ? "" : Description(value.Value); } /// /// 获取格式化字符串 /// /// 数值 /// 空值显示的默认文本 public static string Format(this int number, string defaultValue = "") { if (number == 0) return defaultValue; return number.ToString(); } /// /// 获取格式化字符串 /// /// 数值 /// 空值显示的默认文本 public static string Format(this int? number, string defaultValue = "") { return Format(number.SafeValue(), defaultValue); } /// /// 获取格式化字符串 /// /// 数值 /// 空值显示的默认文本 public static string Format(this decimal number, string defaultValue = "") { if (number == 0) return defaultValue; return string.Format("{0:0.##}", number); } /// /// 获取格式化字符串 /// /// 数值 /// 空值显示的默认文本 public static string Format(this decimal? number, string defaultValue = "") { return Format(number.SafeValue(), defaultValue); } /// /// 获取格式化字符串 /// /// 数值 /// 空值显示的默认文本 public static string Format(this double number, string defaultValue = "") { if (number == 0) return defaultValue; return string.Format("{0:0.##}", number); } /// /// 获取格式化字符串 /// /// 数值 /// 空值显示的默认文本 public static string Format(this double? number, string defaultValue = "") { return Format(number.SafeValue(), defaultValue); } /// /// 获取格式化字符串,带¥ /// /// 数值 public static string FormatRmb(this decimal number) { if (number == 0) return "¥0"; return string.Format("¥{0:0.##}", number); } /// /// 获取格式化字符串,带¥ /// /// 数值 public static string FormatRmb(this decimal? number) { return FormatRmb(number.SafeValue()); } /// /// 获取格式化字符串,带% /// /// 数值 public static string FormatPercent(this decimal number) { if (number == 0) return string.Empty; return string.Format("{0:0.##}%", number); } /// /// 获取格式化字符串,带% /// /// 数值 public static string FormatPercent(this decimal? number) { return FormatPercent(number.SafeValue()); } /// /// 获取格式化字符串,带% /// /// 数值 public static string FormatPercent(this double number) { if (number == 0) return string.Empty; return string.Format("{0:0.##}%", number); } /// /// 获取格式化字符串,带% /// /// 数值 public static string FormatPercent(this double? number) { return FormatPercent(number.SafeValue()); } } }