Reputation: 31
How to convert in C# a double with 1,77 to 1.77?
I have a input text with 1,77 and I want to replace to 1.77.
I have tried
alturaaux =Convert.ToDouble(altura2).ToString(#,##);
but without success.
Upvotes: 0
Views: 137
Reputation: 77876
use TryParse
method like
double ret;
double.TryParse("1,77".Replace(",", "."), out ret);
Upvotes: 0
Reputation: 11
You can first get it to a string than replace the comma to a dot.
string entered = "1,77";
string doubleString = entered.Replace(',', '.');
if(Double.TryParse(doubleString, out number))
return number;
else
return null;
Upvotes: 2