tags:

views:

344

answers:

4

Hi

I have a number like so: 4.47778E+11

Can anyone give me a way of converting that into its number representation easily in c#?

Thanks

+2  A: 
string s = "4.47778e+11";
double d = double.Parse(s);

or

string s = "4.47778e+11";
if (double.TryParse(s,out d))
{
    // number was parsed correctly
}

or for internationalization

double.Parse("4.47778e+11", System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture);

yamspog
Better it would be double.Parse("4.47778e+11", System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture);since first example will fail eg. on Polish localization
Bolek Tekielski
excellent comment. Thanks.
yamspog
A: 

Try this MSDN thread. It's called scientific notation by the way, and a quick google normally solves simple issues.

That's assuming you mean parsing from a string to a float, your question & title are conflicting

mrnye
Hi mryne, sorry the title was confusing. I have a csv file where people open it in excel and then save as csv, the string representation is a large number, but excel will convert by default into scientific notation. My title should have been clearer!
harrisonmeister
A: 
Wim Hollebrandse
A: 

Use Convert:

double value = Convert.ToDouble("4.47778E+11");
Thomas Maierhofer