Mega Code Archive

 
Categories / C# Tutorial / Data Type
 

Decimal parse for currency

using System; using System.Collections.Generic; using System.Globalization; using System.Text; using System.Text.RegularExpressions; using System.Reflection; public class MainClass{    public static void Main(){         string[] money = new string[] { "$0.99", "$0,99", "$1000000.00", "$10.25", "$90,000.00", "$90.000,00", "$1,000,000.00", "$1,000000.00" };         foreach (string m in money)         {             try             {                 Decimal.Parse(m, NumberStyles.Currency);                 Console.WriteLine("!{0}: True", m);             }             catch (FormatException)             {                 Console.WriteLine("!{0}: False", m);             }         }    } } !$0.99: True !$0,99: True !$1000000.00: True !$10.25: True !$90,000.00: True !$90.000,00: False !$1,000,000.00: True !$1,000000.00: True