CSharp examples for System:Converter
Specified object to convert the Decimal.
using System.Xml.Serialization; using System.Text.RegularExpressions; using System.Text; using System.IO;/*from w ww.j a v a2 s . co m*/ using System.Globalization; using System.Collections.Generic; using System; public class Main{ /// <summary> /// Specified object to convert the Decimal. /// </summary> /// <param name="value"></param> /// <param name="numberStyle"></param> /// <param name="formatProvider"></param> /// <returns></returns> public static Decimal? ToDecimal(Object value, NumberStyles numberStyle, IFormatProvider formatProvider) { Decimal x; if (value == null) { return null; } if (value is decimal) { return (Decimal)value; } if (Decimal.TryParse(ToStringOrEmpty(value), numberStyle, formatProvider, out x)) { return x; } return null; } /// <summary> /// Specified object to convert the Decimal. /// </summary> /// <param name="value"></param> /// <returns></returns> public static Decimal? ToDecimal(Object value) { return ToDecimal(value, DefaultDoubleNumberStyle, null); } /// <summary> /// Specified object to convert the Decimal. /// </summary> /// <param name="value"></param> /// <param name="defaultValue"></param> /// <param name="numberStyle"></param> /// <param name="formatProvider"></param> /// <returns></returns> public static Decimal ToDecimal(Object value, Decimal defaultValue, NumberStyles numberStyle, IFormatProvider formatProvider) { return ToDecimal(value, numberStyle, formatProvider) ?? defaultValue; } /// <summary> /// Specified object to convert the Decimal. /// </summary> /// <param name="value"></param> /// <param name="defaultValue"></param> /// <returns></returns> public static Decimal ToDecimal(Object value, Decimal defaultValue) { return ToDecimal(value) ?? defaultValue; } }