Whether a string is a number (includes currencies, decimals, exponents, thousands) - CSharp System

CSharp examples for System:String Number

Description

Whether a string is a number (includes currencies, decimals, exponents, thousands)

Demo Code


using System.Threading.Tasks;
using System.Text.RegularExpressions;
using System.Text;
using System.Net.Mail;
using System.Linq;
using System.Globalization;
using System.Collections.Generic;
using System;/*from w  ww .  j  av  a 2s  .c  o  m*/

public class Main{
        /// <summary>
        /// Whether a string is a number (includes currencies, decimals, exponents, thousands)
        /// </summary>
        public static bool IsNumber(string input)
        {
            double number;
            var success = double.TryParse(input, NumberStyles.Number, 
                new CultureInfo("en-US"), out number);
            return success;
        }
}

Related Tutorials