Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- string to Currency format, with no periods (or commas)
- value = Convert.ToDecimal(value).ToString("C2");
- var stringValue = Convert.ToDecimal(value).ToString("$0.00");
- var formatInfo = (NumberFormatInfo)CultureInfo.CurrentCulture.NumberFormat.Clone();
- formatInfo.CurrencyGroupSeparator = string.Empty;
- var stringValue = Convert.ToDecimal(value).ToString("C", formatInfo);
- var formatInfo = (System.Globalization.NumberFormatInfo)CultureInfo.CurrentCulture.NumberFormat.Clone();
- formatInfo.CurrencyGroupSeparator = ""; // remove the group separator
- Console.WriteLine(2.ToString("C", formatInfo));
- Console.WriteLine(4.ToString("C", formatInfo));
- Console.WriteLine(1000.ToString("C", formatInfo));
- public static class MyExtensions
- {
- public static string GetMoney(this decimal value, bool displayCurrency = false, bool displayPeriods = true)
- {
- string ret = string.Format("{0:C}", value).Substring(displayCurrency ? 0 : 1);
- if (!displayPeriods)
- {
- ret = ret.Replace(",", string.Empty);
- }
- return ret;
- }
- }
- decimal test = 40023.2345M;
- string myValue = test.GetMoney(displayCurrency:true, displayPeriods:false);`
Add Comment
Please, Sign In to add comment