System.Data.SqlTypes.SqlMoney.Parse C# (CSharp) Method

Parse() public static method

public static Parse ( string s ) : SqlMoney
s string
return SqlMoney
        public static SqlMoney Parse(string s)
        {
            // Try parsing the format of '#0.00##' generated by ToString() by using the
            // culture invariant NumberFormatInfo as well as the current culture's format
            //
            decimal d;
            SqlMoney money;

            const NumberStyles SqlNumberStyle =
                     NumberStyles.AllowCurrencySymbol |
                     NumberStyles.AllowDecimalPoint |
                     NumberStyles.AllowParentheses |
                     NumberStyles.AllowTrailingSign |
                     NumberStyles.AllowLeadingSign |
                     NumberStyles.AllowTrailingWhite |
                     NumberStyles.AllowLeadingWhite;

            if (s == SQLResource.s_nullString)
            {
                money = SqlMoney.Null;
            }
            else if (decimal.TryParse(s, SqlNumberStyle, NumberFormatInfo.InvariantInfo, out d))
            {
                money = new SqlMoney(d);
            }
            else
            {
                money = new SqlMoney(decimal.Parse(s, NumberStyles.Currency, NumberFormatInfo.CurrentInfo));
            }

            return money;
        }

Usage Example

Example #1
0
 /**
  * Converts this SqlString instance to SqlString.
  * @return A SqlMoney instance whose Value equals the Value of this SqlString instance.
  */
 public SqlMoney ToSqlMoney()
 {
     return(SqlMoney.Parse(_value));
 }