public static string GetFormattedNumber(string value, ThousandSeparaterTypes separaterType, int decimalPlaces) { bool isNegetive = false; string trailingFormat = string.Empty; if (decimalPlaces > 0) { trailingFormat = "0.".PadRight(decimalPlaces + 2, '0'); } else { trailingFormat = "0"; } switch (separaterType) { case ThousandSeparaterTypes.English: value = double.Parse(value, NumberStyles.AllowThousands | NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign).ToString("###,###,##" + trailingFormat); break; case ThousandSeparaterTypes.Nepali: if (value.StartsWith("-")) { isNegetive = true; } value = value.Replace("-", string.Empty); value = double.Parse(value, NumberStyles.AllowThousands | NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign).ToString("##~##~##~##~##~##~##" + trailingFormat).Replace("~", ",").Trim(','); if (isNegetive) { value = "-" + value; } break; case ThousandSeparaterTypes.NONE: value = double.Parse(value, NumberStyles.AllowThousands | NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign).ToString().Replace(",", string.Empty); break; } return(value); }
public static string GetFormattedNumber(string value, ThousandSeparaterTypes separaterType) { return(GetFormattedNumber(value, separaterType, 0)); }