0

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

4 Answers 4

3
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);

Sign up to request clarification or add additional context in comments.

1 Comment

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
0

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

1 Comment

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!
0

Use

float num = Convert.ToFloat(Convert.ToDouble(s));

But you still lose precision, floats are only precise to 7 digits, so you're better off using just the Convert.ToDouble() (precise to 15 or so digits), so you won't lose any digits in your example.

Comments

0

Use Convert:

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.