Export (0) Print
Expand All

Double.Parse Method

Converts the string representation of a number to its double-precision floating point number equivalent.

Overload List

Converts the string representation of a number to its double-precision floating point number equivalent.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Shared Function Parse(String) As Double
[C#] public static double Parse(string);
[C++] public: static double Parse(String*);
[JScript] public static function Parse(String) : double;

Converts the string representation of a number in a specified culture-specific format to its double-precision floating point number equivalent.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Shared Function Parse(String, IFormatProvider) As Double
[C#] public static double Parse(string, IFormatProvider);
[C++] public: static double Parse(String*, IFormatProvider*);
[JScript] public static function Parse(String, IFormatProvider) : double;

Converts the string representation of a number in a specified style to its double-precision floating point number equivalent.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Shared Function Parse(String, NumberStyles) As Double
[C#] public static double Parse(string, NumberStyles);
[C++] public: static double Parse(String*, NumberStyles);
[JScript] public static function Parse(String, NumberStyles) : double;

Converts the string representation of a number in a specified style and culture-specific format to its double-precision floating point number equivalent.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Shared Function Parse(String, NumberStyles, IFormatProvider) As Double
[C#] public static double Parse(string, NumberStyles, IFormatProvider);
[C++] public: static double Parse(String*, NumberStyles, IFormatProvider*);
[JScript] public static function Parse(String, NumberStyles, IFormatProvider) : double;

Example

The following code sample illustrates the use of Parse, taking a String, an IFormatProvider, and a NumberStyles as parameters:

[Visual Basic] 
Public Class Temperature
    ' Parses the temperature from a string in form
    ' [ws][sign]digits['F|'C][ws]
    Public Shared Function Parse(ByVal s As String, ByVal styles As NumberStyles, ByVal provider As IFormatProvider) As Temperature
        Dim temp As New Temperature()

        If s.TrimEnd(Nothing).EndsWith("'F") Then
            temp.Value = Double.Parse(s.Remove(s.LastIndexOf("'"c), 2), styles, provider)
        Else
            If s.TrimEnd(Nothing).EndsWith("'C") Then
                temp.Celsius = Double.Parse(s.Remove(s.LastIndexOf("'"c), 2), styles, provider)
            Else
                temp.Value = Double.Parse(s, styles, provider)
            End If
        End If
        Return temp
    End Function

    ' The value holder
    Protected m_value As Double

    Public Property Value() As Double
        Get
            Return m_value
        End Get
        Set(ByVal Value As Double)
            m_value = Value
        End Set
    End Property

    Public Property Celsius() As Double
        Get
            Return (m_value - 32) / 1.8
        End Get
        Set(ByVal Value As Double)
            m_value = Value * 1.8 + 32
        End Set
    End Property
End Class

[C#] 
public class Temperature {
    /// <summary>
    /// Parses the temperature from a string in form
    /// [ws][sign]digits['F|'C][ws]
    /// </summary>
    public static Temperature Parse(string s, NumberStyles styles, IFormatProvider provider) {
        Temperature temp = new Temperature();

        if( s.TrimEnd(null).EndsWith("'F") ) {
            temp.Value = Double.Parse( s.Remove(s.LastIndexOf('\''), 2), styles, provider);
        }
        else if( s.TrimEnd(null).EndsWith("'C") ) {
            temp.Celsius = Double.Parse( s.Remove(s.LastIndexOf('\''), 2), styles, provider);
        }
        else {
            temp.Value = Double.Parse(s, styles, provider);
        }

        return temp;
    }

    // The value holder
    protected double m_value;

    public double Value {
        get {
            return m_value;
        }
        set {
            m_value = value;
        }
    }

    public double Celsius {
        get {
            return (m_value-32.0)/1.8;
        }
        set {
            m_value = 1.8*value+32.0;
        }
    }
}

[C++] 
public __gc class Temperature {
   /// <summary>
   /// Parses the temperature from a string in form
   /// [ws][sign]digits['F|'C][ws]
   /// </summary>
public:
   static Temperature* Parse(String* s, NumberStyles styles, IFormatProvider* provider) {
      Temperature* temp = new Temperature();

      if( s->TrimEnd(0)->EndsWith(S"'F") ) {
         temp->Value = Double::Parse( s->Remove(s->LastIndexOf('\''), 2), styles, provider);
      }
      else if( s->TrimEnd(0)->EndsWith(S"'C") ) {
         temp->Celsius = Double::Parse( s->Remove(s->LastIndexOf('\''), 2), styles, provider);
      }
      else {
         temp->Value = Double::Parse(s, styles, provider);
      }

      return temp;
   }

   // The value holder
protected:
   double m_value;

public:
   __property double get_Value() {
      return m_value;
   }
   __property void set_Value( double value ) {
      m_value = value;
   }

   __property double get_Celsius() {
      return (m_value-32.0)/1.8;
   }
   __property void set_Celsius( double value ) {
      m_value = 1.8*value+32.0;
   }

};

[JScript] 
public class Temperature {
    /// <summary>
    /// Parses the temperature from a string in form
    /// [ws][sign]digits['F|'C][ws]
    /// </summary>
    public static function Parse(s : String, styles : NumberStyles, provider : IFormatProvider) : Temperature{
        var temp : Temperature = new Temperature();

        if( s.TrimEnd(null).EndsWith("'F") ) {
            temp.Value = Double.Parse( s.Remove(s.LastIndexOf('\''), 2), styles, provider);
        }
        else if( s.TrimEnd(null).EndsWith("'C") ) {
            temp.Celsius = Double.Parse( s.Remove(s.LastIndexOf('\''), 2), styles, provider);
        }
        else {
            temp.Value = Double.Parse(s, styles, provider);
        }

        return temp;
    }

    // The value holder
    protected var m_value : double;

    public function get Value() : double{
        return m_value;
    }
    
            public function set Value(value : double) {
        m_value = value;
    }

    public function get Celsius() : double {
        return (m_value-32.0)/1.8;
            }
            
            public function set Celsius(value : double) {
        m_value = 1.8*value+32.0;
    }
}

See Also

Double Structure | Double Members | System Namespace

Show:
© 2014 Microsoft