using System.Text.RegularExpressions; namespace WmsMobileServe.Utils; public static class StringUtils { /// /// 判断一个字符串是不是 decimal /// /// /// public static bool IsDecimal(this string? value) { if(string.IsNullOrWhiteSpace(value)) return false; return Regex.IsMatch(value, "^\\d+\\.?\\d+$"); } /// /// 判断一个字符串 是不是 decimal /// /// /// public static bool IsNotDecimal(this string? value) { return !value.IsDecimal(); } /// /// 将字符串转换为 decimal /// /// /// public static decimal? ToDecimal(this string? value) { try { if (!value.IsDecimal()) return default; return Convert.ToDecimal(value); } catch { return default; } } }