Export (0) Print
Expand All

XmlConvert.ToDouble Method

Converts the String to a Double equivalent.

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

public static double ToDouble(
	string s


Type: System.String

The string to convert.

Return Value

Type: System.Double
A Double equivalent of the string.


s is null.


s is not in the correct format.


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;
using System.IO;
using System.Xml;

public class Sample

  public static void Main()
    XmlTextReader reader = new XmlTextReader("orderData.xml");

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

    //Close the reader.

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

<order date="2001-05-03">

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Portable Class Library

Supported in: Portable Class Library

.NET for Windows Store apps

Supported in: Windows 8

.NET for Windows Phone apps

Supported in: Windows Phone 8.1, Windows Phone 8, Silverlight 8.1

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

© 2014 Microsoft