.NET Framework Developer Center >
.NET Development Forums
>
.NET Base Class Library
>
float exponential value interms of 0.00 like ?????
float exponential value interms of 0.00 like ?????
- Hi guys i am getting value in exponential
like :3.14765786987878E-6
I need thsi value in exact way
like : 0.00 some thing it has to come..,
I searched in google and tried in all the ways but i didnt get solution...,
plz help me,
Answers
- Try ToString("e") rather than ToString("F2"), if you would like to see your number output in exponential notation. Further modification of the format string will allow you to limit the number of decimals shown, while still maintaining exponential notation.
See for example http://msdn.microsoft.com/en-us/library/kfsatb94.aspx- Marked As Answer byeryangMSFT, ModeratorMonday, November 16, 2009 3:29 AM
- Hi,
The output is correct, because
3.14765786987878E-6 = 0.0000031476786987878
then, statement:
float.Parse("3.14765786987878E-6", NumberStyles.Float | NumberStyles.AllowExponent).ToString("F2")
is equals to:
float f = 0.0000031476786987878F;
string s = f.ToString("F2"); // s = "0.00"
that's why we got output 0.00.
Thanks,
Eric
Please remember to mark helpful replies as answers and unmark them if they provide no help.- Marked As Answer byeryangMSFT, ModeratorMonday, November 16, 2009 3:28 AM
All Replies
- Are you saying you want to display the value as 0.00000314 or that you want everything rounded to 0.00?
- Hi,
Console.WriteLine("Float="+ float.Parse("3.14765786987878E-6", NumberStyles.Float | NumberStyles.AllowExponent).ToString("F2"));
OUTPUT= 0.00;
I think, when it is
3.14765786987878E-6 = 0.0000031476786987878E
but i want to display in a very short format like 0.31E
- Hi,
The output is correct, because
3.14765786987878E-6 = 0.0000031476786987878
then, statement:
float.Parse("3.14765786987878E-6", NumberStyles.Float | NumberStyles.AllowExponent).ToString("F2")
is equals to:
float f = 0.0000031476786987878F;
string s = f.ToString("F2"); // s = "0.00"
that's why we got output 0.00.
Thanks,
Eric
Please remember to mark helpful replies as answers and unmark them if they provide no help.- Marked As Answer byeryangMSFT, ModeratorMonday, November 16, 2009 3:28 AM
- Try ToString("e") rather than ToString("F2"), if you would like to see your number output in exponential notation. Further modification of the format string will allow you to limit the number of decimals shown, while still maintaining exponential notation.
See for example http://msdn.microsoft.com/en-us/library/kfsatb94.aspx- Marked As Answer byeryangMSFT, ModeratorMonday, November 16, 2009 3:29 AM


