parsing float into string
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
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);
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
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.
Use Convert:
double value = Convert.ToDouble("4.47778E+11");
精彩评论