Specified object to convert the Double. - CSharp System

CSharp examples for System:Converter

Description

Specified object to convert the Double.

Demo Code


using System.Xml.Serialization;
using System.Text.RegularExpressions;
using System.Text;
using System.IO;//w  w  w. ja  v a2 s. c o  m
using System.Globalization;
using System.Collections.Generic;
using System;

public class Main{
        /// <summary>
        /// Specified object to convert the Double.
        /// </summary>
        /// <param name="value"></param>
        /// <param name="numberStyle"></param>
        /// <param name="formatProvider"></param>
        /// <returns></returns>
        public static Double? ToDouble(Object value, NumberStyles numberStyle, IFormatProvider formatProvider)
        {
            Double x;

            if (value == null)
            { return null; }
            if (value is double)
            { return (Double)value; }
            if (Double.TryParse(ToStringOrEmpty(value), numberStyle, formatProvider, out x))
            {
                return x;
            }
            return null;
        }
        /// <summary>
        /// Specified object to convert the Double.
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static Double? ToDouble(Object value)
        {
            return ToDouble(value, DefaultDoubleNumberStyle, null);
        }
        /// <summary>
        /// Specified object to convert the Double.
        /// </summary>
        /// <param name="value"></param>
        /// <param name="defaultValue"></param>
        /// <param name="numberStyle"></param>
        /// <param name="formatProvider"></param>
        /// <returns></returns>
        public static Double ToDouble(Object value, Double defaultValue, NumberStyles numberStyle, IFormatProvider formatProvider)
        {
            return ToDouble(value, numberStyle, formatProvider) ?? defaultValue;
        }
        /// <summary>
        /// Specified object to convert the Double.
        /// </summary>
        /// <param name="value"></param>
        /// <param name="defaultValue"></param>
        /// <returns></returns>
        public static Double ToDouble(Object value, Double defaultValue)
        {
            return ToDouble(value) ?? defaultValue;
        }
}

Related Tutorials