c# - How to convert a string to double

String to double
.net Convert.ToDouble() method converts a specified value to a double-precision floating-point number. this method have few overload. Convert.ToDouble(String) overloaded method allow us to convert the specified string representation of a number to its equivalent double-precision floating-point number. this method is under System namespace.

the Convert.ToDouble(String) method require to pass a parameter named 'value'. this parameter value data type is System.String. this string contains the number to convert. the method return value data type is System.Double. this return value represent a double-precision floating-point number which is equivalent to the number in specified string. its return 0 (zero) if parameter value is null.

the following .net c# example code demonstrate us how can we convert a string object to its equivalent double value in an asp.net application.

<%@ Page Language="C#" AutoEventWireup="true"%>  
<!DOCTYPE html>    
<script runat="server">  
    protected void Button1_Click(object sender, System.EventArgs e)  
        //this section create a string variable.  
        string doubleValueString = "123.2598";  
        Label1.Text = "string of double value..................<br />";
        Label1.Text += doubleValueString;

        //this line convert/parse/transform string to double.
        double doubleValue = Convert.ToDouble(doubleValueString);
        //convert string value to double with culture.
        double doubleValue2 = Convert.ToDouble(doubleValueString,System.Globalization.CultureInfo.InvariantCulture);

        Label1.Text += "<br /><br />converted double from string.........<br />";
        Label1.Text += doubleValue;

        Label1.Text += "<br /><br />converted double from string with culture.........<br />";
        Label1.Text += doubleValue2;

        Label1.Text += "<br /><br />converted double and add 5 .........<br />";
        Label1.Text += doubleValue + 5;
<html xmlns="http://www.w3.org/1999/xhtml">    
<head id="Head1" runat="server">    
    <title>c# example - string to double</title>    
    <form id="form1" runat="server">    
        <h2 style="color:MidnightBlue; font-style:italic;">    
            c# example - string to double
        <hr width="550" align="left" color="Gainsboro" />    
        <br /><br />  
            Text="string to double"    
More c# examples