Ricardo Diz
Ricardo Diz

Reputation: 31

C# - How to convert , in

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

Answers (2)

Rahul
Rahul

Reputation: 77876

use TryParse method like

double ret;
double.TryParse("1,77".Replace(",", "."), out ret);

Upvotes: 0

Katy Pillman
Katy Pillman

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

Related Questions