25

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.

1
  • 1
    Do you wish to represent this in a string? What do you mean by "represent"? Commented Aug 8, 2012 at 4:49

10 Answers 10

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

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

3 Comments

No problem. If you want commas, use "#,#" or "N".
The "whole number" is 340282346638528859811704183484516925440.
@Dan The best answer I have seen in questions like this. Can you show how to do this in C++?
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".

Comments

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

Comments

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!

Comments

2

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

Comments

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

Comments

1

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

1 Comment

I think the c# compiler allows you to define that as a constant but after compilation it is truncated to float.maxvalue.
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

Comments

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

Comments

-1

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.

3 Comments

(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.
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.
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.)

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.