xxxxxxxxxx
// If you need to convert a string to a double you can use this :
var string = "12,05";
var double = Convert.toDouble(string); // This will be a double with the value of 12,05
// If for some reason you need to convert a string with a "." instead of a "," do this :
var string = "12.05";
var double = Convert.ToDouble(string.Replace(".", ",")); // And this will be the same as previous one
xxxxxxxxxx
string numberString = "123.65";
double number;
number = double.Parse(numberString);
Console.WriteLine(number); // Output: 123.65
use the double.Parse() or double.TryParse() method. Here is an example:
xxxxxxxxxx
string str = "3.14159";
double num;
if (double.TryParse(str, out num))
{
Console.WriteLine("The number is: " + num);
}
else
{
Console.WriteLine("Invalid input");
}
//double.TryParse() is used to attempt to parse the string str as a double.
//If the conversion is successful, the num variable will hold the double value,
//and the program will output "The number is: 3.14159". If the conversion fails,
//the program will output "Invalid input".