maximum value for type float in c#

前端 未结 8 1615
你的背包
你的背包 2021-02-12 14:27

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 withou

相关标签:
8条回答
  • 2021-02-12 15:05

    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
    
    0 讨论(0)
  • 2021-02-12 15:10

    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
    
    0 讨论(0)
  • 2021-02-12 15:12

    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

    0 讨论(0)
  • 2021-02-12 15:18

    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!

    0 讨论(0)
  • 2021-02-12 15:26

    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
    
    0 讨论(0)
  • 2021-02-12 15:29

    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.

    0 讨论(0)
提交回复
热议问题