When I do this:
float x = float.MaxValue;
I have the result: 3.40282347E+38
What is E+38? how can I represent the maximum number without this symbol?
msdn says RANGE: ±1.5 × 10^−45 to ±3.4 × 10^38, but that did not help me.
When I do this:
float x = float.MaxValue;
I have the result: 3.40282347E+38
What is E+38? how can I represent the maximum number without this symbol?
msdn says RANGE: ±1.5 × 10^−45 to ±3.4 × 10^38, but that did not help me.
The "E+38" format is the default. If you'd like to see the whole number, specify a different format like this:
float.MaxValue.ToString("#")
This will result in:
340282300000000000000000000000000000000
Here are some additional formats: http://msdn.microsoft.com/en-us/library/system.globalization.numberformatinfo.aspx
This is called E-Notation (exponential notation), and is used with scientific notation.
From the E Notation section of the Wikipedia article on Scientific Notation:
Because super-scripted exponents like 10^7 cannot always be conveniently displayed, the letter E or e is often used to represent times ten raised to the power of (which would be written as "x 10^b") and is followed by the value of the exponent.
So, 3.40282347E+38
equals 3.40282347 * 10
38
and would be read "3.40282347 times 10 to the power of 38".
Try the following code:
float f = float.MaxValue;
Console.WriteLine("Origianl Value: " + f);
Console.WriteLine("With Zeros:" + f.ToString("0"));
Value
Origianl Value: 3.402823E+38
With Zeros:340282300000000000000000000000000000000
That is Scientific Notation.
5E+2 =
5 x 10 ^ 2 =
5 x 10 * 10 =
5 * 100 =
500
In other words, that's how many decimal places you move the decimal point to calculate the result. Take 5, move it over 2 places, end up with 500. In your example, you need to take your number, 3.40282347
and move the decimal place over 38 times!
3.4e38 is 3.4 * 10^38 or 340000000000 ... (37 zeros)
additional information:
http://msdn.microsoft.com/en-us/library/b1e65aza(v=vs.71).aspx
It's approx. 340 000 000 000 000 000 000 000 000 000 000 000 000
If you use Dan's code, you'll get this as a result:
340282300000000000000000000000000000000
The maximum number of the float without exponent is: 340282356779733661637539395458142568447.9f
Old question, but here's the min and max in string format.
Using float.Parse
-340282356779733642999999999999999999999 to 340282356779733642999999999999999999999
Using float.MinValue.ToString("#") and float.MaxValue.ToString("#")
-340282300000000000000000000000000000000 to 340282300000000000000000000000000000000
Using float.MinValue.ToString() and float.MaxValue.ToString()
-3.402823E+38 to 3.402823E+38
Sorry to necro an old thread but google lead me here and I didn't find a satisfactory answer. I'm sure google will lead someone else here.
The float.h library includes the maximum values for float and others in c. FLOAT_MAX is equal to 340282346638528859811704183484516925440, that is the maximum value that float can store.
I'm not an expert in C but I would imagine this value is universal and wouldn't depend on a x32 or x64 operating system.
The answers showing float.MaxValue
using ToString
are not correct.
Those answers state float.MaxValue
is :
var f1 = 340282300000000000000000000000000000000f;
That is only is what C# produces when converting float.MaxValue
to string.
However, float.MaxValue
is defined in System.Single
as 3.40282347E+38F
So the actual answer is:
var f2 = 340282347000000000000000000000000000000f;
Also note, a compile defect will allow constant values higher than this to be used as a float. However upon compliation, C# will trunacted those values to float.MaxValue
. For example:
var f3 = 340282356699999999999999999999999999999f;
var f4 = 340282356760000000000000000000000000000f;
var f5 = 340282356779733661637539395458142568447.9f;
Here f5 (340282356779733661637539395458142568447.9f
) is the actual maximum constant you can define. Again, this is truncated to float.MaxValue
.
This can all be verified:
var equals_1 = f1 == f; // false
var equals_2 = f2 == float.MaxValue; // true
var equals_3 = f3 == float.MaxValue; // true
var equals_4 = f3 == float.MaxValue; // true
var equals_4 = f5 == float.MaxValue; // true