Windows apps
Collapse the table of content
Expand the table of content
Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

XmlConvert::ToDouble Method (String^)

 

Converts the String to a Double equivalent.

Namespace:   System.Xml
Assembly:  System.Xml (in System.Xml.dll)

public:
static double ToDouble(
	String^ s
)

Parameters

s
Type: System::String^

The string to convert.

Return Value

Type: System::Double

A Double equivalent of the string.

Exception Condition
ArgumentNullException

s is null.

FormatException

s is not in the correct format.

OverflowException

s represents a number less than Double::MinValue or greater than Double::MaxValue.

If s is INF or -INF, this method returns Double.PositiveInfinity or Double.NegativeInfinity respectively.

The following example uses ToDouble and ToDateTime to read strongly typed data.

#using <System.dll>
#using <System.xml.dll>

using namespace System;
using namespace System::IO;
using namespace System::Xml;
int main()
{
   XmlTextReader^ reader = gcnew XmlTextReader( "orderData.xml" );

   //Parse the file and pull out the order date and price.
   while ( reader->Read() )
   {
      if ( reader->NodeType == XmlNodeType::Element )
      {
         if ( reader->Name->Equals( "order" ) )
         {
            DateTime orderDate = XmlConvert::ToDateTime( reader->GetAttribute( "date" ) );
            Console::WriteLine( "order date: {0}", orderDate.ToString() );
         }
         else
         if ( reader->Name->Equals( "price" ) )
         {
            Double price = XmlConvert::ToDouble( reader->ReadInnerXml() );
            Console::WriteLine( "price: {0}", price );
         }
      }
   }


   //Close the reader.
   reader->Close();
}

The example uses the file, orderData.xml, as input.

<order date="2001-05-03">
  <orderID>367A54</orderID>
  <custID>32632</custID>
  <price>19.95</price>
</order>

Universal Windows Platform
Available since 8
.NET Framework
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1
Return to top
Show:
© 2017 Microsoft