private static string ToStringUsDigitsFormattingInternal( dynamic number, DigitsFormattingSettings digitsFormattingSettings = DigitsFormattingSettings.None, int precesion = 2) { var formattedDigits = string.Empty; var currentNoComaFormatSpecifier = string.Concat("#.", new string('0', precesion)); var currentComaFormatSpecifier = string.Concat("##,#.", new string('0', precesion)); formattedDigits = digitsFormattingSettings.HasFlag(DigitsFormattingSettings.NoComma) ? number.ToString(currentNoComaFormatSpecifier, usCultureInfo) : number.ToString(currentComaFormatSpecifier, usCultureInfo); if (digitsFormattingSettings.HasFlag(DigitsFormattingSettings.PrefixDollar)) { formattedDigits = string.Concat("$", formattedDigits); } if (digitsFormattingSettings.HasFlag(DigitsFormattingSettings.PrefixMinus)) { formattedDigits = string.Concat("-", formattedDigits); } if (digitsFormattingSettings.HasFlag(DigitsFormattingSettings.SufixDollar)) { formattedDigits = string.Concat(formattedDigits, "$"); } return(formattedDigits); }
private static string ToStringUsDigitsFormattingInternal <T>( T number, DigitsFormattingSettings digitsFormattingSettings = DigitsFormattingSettings.None, int precesion = 2) where T : struct, IComparable, IComparable <T>, IConvertible, IEquatable <T>, IFormattable { string formattedDigits = string.Empty; string currentNoComaFormatSpecifier = string.Concat("#.", new string('0', precesion)); string currentComaFormatSpecifier = string.Concat("##,#.", new string('0', precesion)); formattedDigits = digitsFormattingSettings.HasFlag(DigitsFormattingSettings.NoComma) ? number.ToString(currentNoComaFormatSpecifier, usCultureInfo) : number.ToString(currentComaFormatSpecifier, usCultureInfo); if (digitsFormattingSettings.HasFlag(DigitsFormattingSettings.PrefixDollar)) { formattedDigits = string.Concat("$", formattedDigits); } if (digitsFormattingSettings.HasFlag(DigitsFormattingSettings.PrefixMinus)) { formattedDigits = string.Concat("-", formattedDigits); } if (digitsFormattingSettings.HasFlag(DigitsFormattingSettings.SufixDollar)) { formattedDigits = string.Concat(formattedDigits, "$"); } return(formattedDigits); }
public static string ToStringUsDigitsFormatting( this decimal number, DigitsFormattingSettings digitsFormattingSettings = DigitsFormattingSettings.None, int precesion = 2) { var result = ToStringUsDigitsFormattingInternal(number, digitsFormattingSettings, precesion); return(result); }