Created
September 12, 2015 14:39
-
-
Save angelovstanton/d6c614bc6e7eb7b0b42a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment