24

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.

phuclv
  • 37,963
  • 15
  • 156
  • 475
Tyrael Archangel
  • 477
  • 1
  • 3
  • 8

10 Answers10

39

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

Dan
  • 9,717
  • 4
  • 47
  • 65
13

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 * 1038 and would be read "3.40282347 times 10 to the power of 38".

Adam Porad
  • 14,193
  • 3
  • 31
  • 56
6

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
Habib
  • 219,104
  • 29
  • 407
  • 436
3

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!

jb.
  • 9,921
  • 12
  • 54
  • 90
1

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

LOZ
  • 1,169
  • 2
  • 16
  • 43
1

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
Frederik Gheysels
  • 56,135
  • 11
  • 101
  • 154
1

The maximum number of the float without exponent is: 340282356779733661637539395458142568447.9f

0

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
Vnsax
  • 67
  • 4
0

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.

  • 1
    (a) `FLT_MAX` -- not `FLOAT_MAX` -- actually _does_ vary from system to system, or compiler to compiler, although it's at *least* 1E+37 (b) this question is about C#, not C. – Paul Roub Sep 01 '20 at 22:02
  • first, this should be its own question. second, the max value of an IEEE floating point value is defined by international standard. it's impossible to store "all values in range" within a 32bit space and loss of precision occurs values greater than approximately 2^24 -- a similar loss of precision happens to fraction values. again this is because the available binary space for storage, and, .NET follows IEEE 754-1985 rounding rules. A new standard was published in 2008. Either way, float can store values greater than `340282346638528859811704183484516925440` with significant loss of precision. – Shaun Wilson Feb 15 '21 at 04:03
  • this is neither language-specific nor platform/architecture-specific. the choice of what to provide in constants found in various sources is not dictated by IEEE standard, and will vary. by spec, the FLT_MAX in your C distribution is technically incorrect, it is too large a value to store in a 32bit space and necessarily would be rounded. the largest normal integer which can be stored in a 32bit space (unsigned) is 4,294,967,295 (anything greater than this demands loss of precision.) – Shaun Wilson Feb 15 '21 at 04:06
0

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
Alexander Higgins
  • 6,765
  • 1
  • 23
  • 41