Currency format is very important for all business related transactions. Here we are using Globalization namespace. If we give input "545.545" to GetCurrencyFormat function. we will get US$ 545.55.
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Globalization; namespace premiumvalue { class Program { static void Main(string[] args) { Console.WriteLine(GetCurrencyFormat("545.545")); Console.ReadLine(); } public static string GetCurrencyFormat(string amout) { string returnValue = string.Empty; try { //http://aspnettutorialonline.blogspot.com NumberFormatInfo nfi = new NumberFormatInfo(); nfi.CurrencySymbol = "US$"; decimal amountValue = Convert.ToDecimal(amout); returnValue = String.Format(nfi, "{0:C}", amountValue); string[] decimalValues = returnValue.Split('.'); if (decimalValues.Length > 1) { if (int.Parse(decimalValues[1]) <= 0) { returnValue = decimalValues[0]; } } //http://aspnettutorialonline.blogspot.com } catch (Exception ex) { throw ex; } return returnValue; } } }
Output:
If you have any queries or suggestions, please feel free to ask in comments section.
Post a Comment
Please give your valuable feedback on this post. You can submit any ASP.NET article here. We will post that article in this website by your name.