C#中float类型的最大值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11857797/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-09 19:31:46  来源:igfitidea点击:

maximum value for type float in c#

c#

提问by Tyrael Archangel

when i do this:

当我这样做时:

float x = float.MaxValue;

I have the result: 3.40282347E+38

我有结果:3.40282347E+38

What is E+38? how can I represent the maximum number without this symbol?

什么是E+38?如果没有这个符号,我如何表示最大数量?

msdn says RANGE: ±1.5 × 10^?45 to ±3.4 × 10^38, but that did not help me.

msdn 说范围:±1.5 × 10^?45 到 ±3.4 × 10^38,但这对我没有帮助。

回答by LOZ

3.4e38 is 3.4 * 10^38 or 340000000000 ... (37 zeros)

3.4e38 是 3.4 * 10^38 或 340000000000 ...(37 个零)

additional information:

附加信息:

http://msdn.microsoft.com/en-us/library/b1e65aza(v=vs.71).aspx

http://msdn.microsoft.com/en-us/library/b1e65aza(v=vs.71).aspx

回答by Dan

The "E+38" format is the default. If you'd like to see the whole number, specify a different format like this:

“E+38”格式是默认格式。如果您想查看整数,请指定不同的格式,如下所示:

float.MaxValue.ToString("#")

This will result in:

这将导致:

340282300000000000000000000000000000000

Here are some additional formats: http://msdn.microsoft.com/en-us/library/system.globalization.numberformatinfo.aspx

以下是一些其他格式:http: //msdn.microsoft.com/en-us/library/system.globalization.numberformatinfo.aspx

回答by Frederik Gheysels

It's approx. 340 000 000 000 000 000 000 000 000 000 000 000 000

这是大约。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:

如果你使用 Dan 的代码,你会得到这样的结果:

340282300000000000000000000000000000000

回答by Adam Porad

This is called E-Notation(exponential notation), and is used with scientific notation.

这称为E-Notation(指数记数法),与科学记数法一起使用。

From the E Notation section of the Wikipedia article on Scientific Notation:

来自维基百科关于科学记数法的文章E 记数法部分

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.

因为像 10^7 这样的上标指数不能总是方便地显示,所以字母 E 或 e 通常用于表示 10 次幂(将写成“x 10^b”),然后是指数的值。

So, 3.40282347E+38equals 3.40282347 * 1038and would be read "3.40282347 times 10 to the power of 38".

因此,3.40282347E+38等于3.40282347 * 1038并且将被读取为“3.40282347 乘以 10 的 38 次方”。

回答by jb.

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.40282347and move the decimal place over 38 times!

换句话说,这就是您移动小数点来计算结果的小数位数。取 5,将其移动 2 位,最终得到 500。在您的示例中,您需要取您的数字,3.40282347并将小数点移动 38 次!

回答by Habib

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

回答by Vnsax

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