float和double有什么区别?

时间:2021-04-03 16:35:06

I've read about the difference between double precision and single precision. However, in most cases, float and double seem to be interchangeable, i.e. using one or the other does not seem to affect the results. Is this really the case? When are floats and doubles interchangeable? What are the differences between them?

我已经读过双精度和单精度之间的区别。但是,在大多数情况下,浮动和双重似乎是可以互换的,即使用一个或另一个似乎不会影响结果。这是真的吗?浮动和双打什么时候可以互换?它们之间有什么区别?

11 个解决方案

#1


408  

Huge difference.

As the name implies, a double has 2x the precision of float[1]. In general a double has 15 decimal digits of precision, while float has 7.

顾名思义,double的精度为float [1]的2倍。通常,double有15个十进制数字的精度,而float有7个。

Here's how the number of digits are calculated:

以下是计算位数的方式:

double has 52 mantissa bits + 1 hidden bit: log(253)÷log(10) = 15.95 digits

double有52个尾数位+ 1个隐藏位:log(253)÷log(10)= 15.95位

float has 23 mantissa bits + 1 hidden bit: log(224)÷log(10) = 7.22 digits

float有23个尾数位+ 1个隐藏位:log(224)÷log(10)= 7.22位

This precision loss could lead to truncation errors much easier to float up, e.g.

这种精确度损失可能导致截断错误更容易浮动,例如,

float a = 1.f / 81;float b = 0;for (int i = 0; i < 729; ++ i)    b += a;printf("%.7g\n", b); // prints 9.000023

while

double a = 1.0 / 81;double b = 0;for (int i = 0; i < 729; ++ i)    b += a;printf("%.15g\n", b); // prints 8.99999999999996

Also, the maximum value of float is about 3e38, but double is about 1.7e308, so using float can hit "infinity" (i.e. a special floating-point number) much more easily than double for something simple, e.g. computing the factorial of 60.

此外,float的最大值约为3e38,但是double约为1.7e308,因此使用float可以更容易地击中“无穷大”(即一个特殊的浮点数),而对于简单的事物,例如,计算60的阶乘。

During testing, maybe a few test cases contain these huge numbers, which may cause your programs to fail if you use floats.

在测试期间,可能有一些测试用例包含这些巨大的数字,如果使用浮点数,可能会导致程序失败。


Of course, sometimes, even double isn't accurate enough, hence we sometimes have long double[1] (the above example gives 9.000000000000000066 on Mac), but all floating point types suffer from round-off errors, so if precision is very important (e.g. money processing) you should use int or a fraction class.

当然,有时候,即使double也不够准确,因此我们有时会有很长的双倍[1](上面的例子在Mac上给出了9.000000000000000066),但所有浮点类型都有四舍五入的错误,所以如果精度非常重要(例如货币处理)你应该使用int或分数类。


Furthermore, don't use += to sum lots of floating point numbers, as the errors accumulate quickly. If you're using Python, use fsum. Otherwise, try to implement the Kahan summation algorithm.

此外,不要使用+ =来汇总大量浮点数,因为错误会很快累积。如果您使用的是Python,请使用fsum。否则,尝试实现Kahan求和算法。


[1]: The C and C++ standards do not specify the representation of float, double and long double. It is possible that all three are implemented as IEEE double-precision. Nevertheless, for most architectures (gcc, MSVC; x86, x64, ARM) float is indeed a IEEE single-precision floating point number (binary32), and double is a IEEE double-precision floating point number (binary64).

[1]:C和C ++标准没有指定float,double和long double的表示。所有这三个都可以实现为IEEE双精度。然而,对于大多数体系结构(gcc,MSVC; x86,x64,ARM),float实际上是IEEE单精度浮点数(binary32),而double是IEEE双精度浮点数(binary64)。

#2


50  

Here is what the standard C99 (ISO-IEC 9899 6.2.5 §10) or C++2003 (ISO-IEC 14882-2003 3.1.9 §8) standards say:

这是标准C99(ISO-IEC 98996.2.5§10)或C ++ 2003(ISO-IEC 14882-20033.1.9§8)标准所说的:

There are three floating point types: float, double, and long double. The type double provides at least as much precision as float, and the type long double provides at least as much precision as double. The set of values of the type float is a subset of the set of values of the type double; the set of values of the type double is a subset of the set of values of the type long double.

有三种浮点类型:float,double和long double。 double类型提供至少与float一样多的精度,long double类型提供至少与double一样多的精度。 float类型的值集是double类型的值集的子集; double类型的值集是long double类型的值集的子集。

The C++ standard adds:

C ++标准增加了:

The value representation of floating-point types is implementation-defined.

浮点类型的值表示是实现定义的。

I would suggest having a look at the excellent What Every Computer Scientist Should Know About Floating-Point Arithmetic that covers the IEEE floating-point standard in depth. You'll learn about the representation details and you'll realize there is a tradeoff between magnitude and precision. The precision of the floating point representation increases as the magnitude decreases, hence floating point numbers between -1 and 1 are those with the most precision.

我建议看看优秀的每个计算机科学家应该知道的关于浮点算术的内容,该算法深入涵盖了IEEE浮点标准。您将了解表示细节,您将意识到在幅度和精度之间存在权衡。浮点表示的精度随着幅度的减小而增加,因此-1和1之间的浮点数是具有最高精度的浮点数。

#3


25  

Given a quadratic equation: x2 − 4.0000000 x + 3.9999999 = 0, the exact roots to 10 significant digits are, r1 = 2.000316228 and r2 = 1.999683772.

给定二次方程:x2 - 4.0000000 x + 3.9999999 = 0,精确根到10位有效数字,r1 = 2.000316228,r2 = 1.999683772。

Using float and double, we can write a test program:

使用float和double,我们可以编写一个测试程序:

#include <stdio.h>#include <math.h>void dbl_solve(double a, double b, double c){    double d = b*b - 4.0*a*c;    double sd = sqrt(d);    double r1 = (-b + sd) / (2.0*a);    double r2 = (-b - sd) / (2.0*a);    printf("%.5f\t%.5f\n", r1, r2);}void flt_solve(float a, float b, float c){    float d = b*b - 4.0f*a*c;    float sd = sqrtf(d);    float r1 = (-b + sd) / (2.0f*a);    float r2 = (-b - sd) / (2.0f*a);    printf("%.5f\t%.5f\n", r1, r2);}   int main(void){    float fa = 1.0f;    float fb = -4.0000000f;    float fc = 3.9999999f;    double da = 1.0;    double db = -4.0000000;    double dc = 3.9999999;    flt_solve(fa, fb, fc);    dbl_solve(da, db, dc);    return 0;}  

Running the program gives me:

运行程序给了我:

2.00000 2.000002.00032 1.99968

Note that the numbers aren't large, but still you get cancellation effects using float.

请注意,数字不是很大,但仍然可以使用float获得取消效果。

(In fact, the above is not the best way of solving quadratic equations using either single- or double-precision floating-point numbers, but the answer remains unchanged even if one uses a more stable method.)

(事实上​​,上述不是使用单精度或双精度浮点数求解二次方程的最佳方法,但即使使用更稳定的方法,答案也保持不变。)

#4


18  

  • A double is 64 and single precision(float) is 32 bits.
  • double是64,单精度(float)是32位。

  • The double has a bigger mantissa (the integer bits of the real number).
  • double有一个更大的尾数(实数的整数位)。

  • Any inaccuracies will be smaller in the double.
  • 双倍的任何不准确性都会变小。

#5


11  

The size of the numbers involved in the float-point calculations is not the most relevant thing. It's the calculation that is being performed that is relevant.

浮点计算中涉及的数字大小并不是最相关的。这是正在执行的相关计算。

In essence, if you're performing a calculation and the result is an irrational number or recurring decimal, then there will be rounding errors when that number is squashed into the finite size data structure you're using. Since double is twice the size of float then the rounding error will be a lot smaller.

本质上,如果您正在执行计算并且结果是无理数或重复的小数,那么当该数被压缩到您正在使用的有限大小数据结构中时,将存在舍入误差。由于double是float的两倍,因此舍入误差会小很多。

The tests may specifically use numbers which would cause this kind of error and therefore tested that you'd used the appropriate type in your code.

测试可能会专门使用会导致此类错误的数字,因此测试您在代码中使用了适当的类型。

#6


8  

Floats have less precision than doubles. Although you already know, read What WE Should Know About Floating-Point Arithmetic for better understanding.

浮点数的精度低于双精度数。虽然您已经知道,但请阅读我们应该了解的关于浮点运算的内容以便更好地理解。

#7


8  

Type float, 32 bits long, has a precision of 7 digits. While it may store values with very large or very small range (+/- 3.4 * 10^38 or * 10^-38), it has only 7 significant digits.

类型为float,长32位,精度为7位。虽然它可以存储非常大或非常小范围(+/- 3.4 * 10 ^ 38或* 10 ^ -38)的值,但它只有7位有效数字。

Type double, 64 bits long, has a bigger range (*10^+/-308) and 15 digits precision.

类型为double,64位长,具有更大的范围(* 10 ^ + / - 308)和15位精度。

Type long double is nominally 80 bits, though a given compiler/OS pairing may store it as 12-16 bytes for alignment purposes. The long double has an exponent that just ridiculously huge and should have 19 digits precision. Microsoft, in their infinite wisdom, limits long double to 8 bytes, the same as plain double.

类型long double名义上是80位,但是给定的编译器/ OS配对可以将其存储为12-16个字节以用于对齐目的。 long double有一个非常庞大的指数,应该有19位数的精度。微软凭借其无限的智慧,将长双倍限制为8字节,与普通双重相同。

Generally speaking, just use type double when you need a floating point value/variable. Literal floating point values used in expressions will be treated as doubles by default, and most of the math functions that return floating point values return doubles. You'll save yourself many headaches and typecastings if you just use double.

一般来说,只需在需要浮点值/变量时使用double类型。默认情况下,表达式中使用的文字浮点值将被视为双精度值,并且返回浮点值的大多数数学函数都会返回双精度值。如果你只使用双倍,你会省去许多头痛和类型。

#8


7  

I just ran into a error that took me forever to figure out and potentially can give you a good example of float precision.

我刚刚遇到一个错误,让我永远弄明白,并且可能会给你一个漂浮精度的好例子。

#include <iostream>#include <iomanip>int main(){  for(float t=0;t<1;t+=0.01){     std::cout << std::fixed << std::setprecision(6) << t << std::endl;  }}

The output is

输出是

0.0000000.0100000.0200000.0300000.0400000.0500000.0600000.0700000.0800000.0900000.1000000.1100000.1200000.1300000.1400000.1500000.1600000.1700000.1800000.1900000.2000000.2100000.2200000.2300000.2400000.2500000.2600000.2700000.2800000.2900000.3000000.3100000.3200000.3300000.3400000.3500000.3600000.3700000.3800000.3900000.4000000.4100000.4200000.4300000.4400000.4500000.4600000.4700000.4800000.4900000.5000000.5100000.5200000.5300000.5400000.5500000.5600000.5700000.5800000.5900000.6000000.6100000.6200000.6300000.6400000.6500000.6600000.6700000.6800000.6900000.7000000.7100000.7200000.7300000.7400000.7500000.7600000.7700000.7800000.7900000.8000000.8100000.8200000.8300000.8399990.8499990.8599990.8699990.8799990.8899990.8999990.9099990.9199990.9299990.9399990.9499990.9599990.9699990.9799990.9899990.999999

As you can see after 0.83, the precision runs down significantly.

正如您在0.83之后看到的那样,精度显着下降。

However, if I set up t as double, such an issue won't happen.

但是,如果我将t设置为double,则不会发生这样的问题。

It took me five hours to realize this minor error, which ruined my program.

我花了五个小时才意识到这个小错误,这毁了我的程序。

#9


3  

When using floating point numbers you cannot trust that your local tests will be exactly the same as the tests that are done on the server side. The environment and the compiler are probably different on you local system and where the final tests are run. I have seen this problem many times before in some TopCoder competitions especially if you try to compare two floating point numbers.

使用浮点数时,您不能相信您的本地测试将与服务器端的测试完全相同。环境和编译器可能与您本地系统和运行最终测试的位置不同。我之前在一些TopCoder比赛中已经多次看到这个问题,特别是如果你试图比较两个浮点数。

#10


2  

The built-in comparison operations differ as in when you compare 2 numbers with floating point, the difference in data type (i.e. float or double) may result in different outcomes.

内置比较操作的不同之处在于,当您将2个数字与浮点数进行比较时,数据类型的差异(即浮点数或双精度数)可能会导致不同的结果。

#11


-1  

Unlike an int (whole number), a float have a decimal point, and so can a double.But the difference between the two is that a double is twice as detailed as a float, meaning that it can have double the amount of numbers after the decimal point.

与int(整数)不同,float有一个小数点,所以double也可以。但是两者之间的区别在于double是float的两倍,这意味着它可以有两倍的数字。小数点。

#1


408  

Huge difference.

As the name implies, a double has 2x the precision of float[1]. In general a double has 15 decimal digits of precision, while float has 7.

顾名思义,double的精度为float [1]的2倍。通常,double有15个十进制数字的精度,而float有7个。

Here's how the number of digits are calculated:

以下是计算位数的方式:

double has 52 mantissa bits + 1 hidden bit: log(253)÷log(10) = 15.95 digits

double有52个尾数位+ 1个隐藏位:log(253)÷log(10)= 15.95位

float has 23 mantissa bits + 1 hidden bit: log(224)÷log(10) = 7.22 digits

float有23个尾数位+ 1个隐藏位:log(224)÷log(10)= 7.22位

This precision loss could lead to truncation errors much easier to float up, e.g.

这种精确度损失可能导致截断错误更容易浮动,例如,

float a = 1.f / 81;float b = 0;for (int i = 0; i < 729; ++ i)    b += a;printf("%.7g\n", b); // prints 9.000023

while

double a = 1.0 / 81;double b = 0;for (int i = 0; i < 729; ++ i)    b += a;printf("%.15g\n", b); // prints 8.99999999999996

Also, the maximum value of float is about 3e38, but double is about 1.7e308, so using float can hit "infinity" (i.e. a special floating-point number) much more easily than double for something simple, e.g. computing the factorial of 60.

此外,float的最大值约为3e38,但是double约为1.7e308,因此使用float可以更容易地击中“无穷大”(即一个特殊的浮点数),而对于简单的事物,例如,计算60的阶乘。

During testing, maybe a few test cases contain these huge numbers, which may cause your programs to fail if you use floats.

在测试期间,可能有一些测试用例包含这些巨大的数字,如果使用浮点数,可能会导致程序失败。


Of course, sometimes, even double isn't accurate enough, hence we sometimes have long double[1] (the above example gives 9.000000000000000066 on Mac), but all floating point types suffer from round-off errors, so if precision is very important (e.g. money processing) you should use int or a fraction class.

当然,有时候,即使double也不够准确,因此我们有时会有很长的双倍[1](上面的例子在Mac上给出了9.000000000000000066),但所有浮点类型都有四舍五入的错误,所以如果精度非常重要(例如货币处理)你应该使用int或分数类。


Furthermore, don't use += to sum lots of floating point numbers, as the errors accumulate quickly. If you're using Python, use fsum. Otherwise, try to implement the Kahan summation algorithm.

此外,不要使用+ =来汇总大量浮点数,因为错误会很快累积。如果您使用的是Python,请使用fsum。否则,尝试实现Kahan求和算法。


[1]: The C and C++ standards do not specify the representation of float, double and long double. It is possible that all three are implemented as IEEE double-precision. Nevertheless, for most architectures (gcc, MSVC; x86, x64, ARM) float is indeed a IEEE single-precision floating point number (binary32), and double is a IEEE double-precision floating point number (binary64).

[1]:C和C ++标准没有指定float,double和long double的表示。所有这三个都可以实现为IEEE双精度。然而,对于大多数体系结构(gcc,MSVC; x86,x64,ARM),float实际上是IEEE单精度浮点数(binary32),而double是IEEE双精度浮点数(binary64)。

#2


50  

Here is what the standard C99 (ISO-IEC 9899 6.2.5 §10) or C++2003 (ISO-IEC 14882-2003 3.1.9 §8) standards say:

这是标准C99(ISO-IEC 98996.2.5§10)或C ++ 2003(ISO-IEC 14882-20033.1.9§8)标准所说的:

There are three floating point types: float, double, and long double. The type double provides at least as much precision as float, and the type long double provides at least as much precision as double. The set of values of the type float is a subset of the set of values of the type double; the set of values of the type double is a subset of the set of values of the type long double.

有三种浮点类型:float,double和long double。 double类型提供至少与float一样多的精度,long double类型提供至少与double一样多的精度。 float类型的值集是double类型的值集的子集; double类型的值集是long double类型的值集的子集。

The C++ standard adds:

C ++标准增加了:

The value representation of floating-point types is implementation-defined.

浮点类型的值表示是实现定义的。

I would suggest having a look at the excellent What Every Computer Scientist Should Know About Floating-Point Arithmetic that covers the IEEE floating-point standard in depth. You'll learn about the representation details and you'll realize there is a tradeoff between magnitude and precision. The precision of the floating point representation increases as the magnitude decreases, hence floating point numbers between -1 and 1 are those with the most precision.

我建议看看优秀的每个计算机科学家应该知道的关于浮点算术的内容,该算法深入涵盖了IEEE浮点标准。您将了解表示细节,您将意识到在幅度和精度之间存在权衡。浮点表示的精度随着幅度的减小而增加,因此-1和1之间的浮点数是具有最高精度的浮点数。

#3


25  

Given a quadratic equation: x2 − 4.0000000 x + 3.9999999 = 0, the exact roots to 10 significant digits are, r1 = 2.000316228 and r2 = 1.999683772.

给定二次方程:x2 - 4.0000000 x + 3.9999999 = 0,精确根到10位有效数字,r1 = 2.000316228,r2 = 1.999683772。

Using float and double, we can write a test program:

使用float和double,我们可以编写一个测试程序:

#include <stdio.h>#include <math.h>void dbl_solve(double a, double b, double c){    double d = b*b - 4.0*a*c;    double sd = sqrt(d);    double r1 = (-b + sd) / (2.0*a);    double r2 = (-b - sd) / (2.0*a);    printf("%.5f\t%.5f\n", r1, r2);}void flt_solve(float a, float b, float c){    float d = b*b - 4.0f*a*c;    float sd = sqrtf(d);    float r1 = (-b + sd) / (2.0f*a);    float r2 = (-b - sd) / (2.0f*a);    printf("%.5f\t%.5f\n", r1, r2);}   int main(void){    float fa = 1.0f;    float fb = -4.0000000f;    float fc = 3.9999999f;    double da = 1.0;    double db = -4.0000000;    double dc = 3.9999999;    flt_solve(fa, fb, fc);    dbl_solve(da, db, dc);    return 0;}  

Running the program gives me:

运行程序给了我:

2.00000 2.000002.00032 1.99968

Note that the numbers aren't large, but still you get cancellation effects using float.

请注意,数字不是很大,但仍然可以使用float获得取消效果。

(In fact, the above is not the best way of solving quadratic equations using either single- or double-precision floating-point numbers, but the answer remains unchanged even if one uses a more stable method.)

(事实上​​,上述不是使用单精度或双精度浮点数求解二次方程的最佳方法,但即使使用更稳定的方法,答案也保持不变。)

#4


18  

  • A double is 64 and single precision(float) is 32 bits.
  • double是64,单精度(float)是32位。

  • The double has a bigger mantissa (the integer bits of the real number).
  • double有一个更大的尾数(实数的整数位)。

  • Any inaccuracies will be smaller in the double.
  • 双倍的任何不准确性都会变小。

#5


11  

The size of the numbers involved in the float-point calculations is not the most relevant thing. It's the calculation that is being performed that is relevant.

浮点计算中涉及的数字大小并不是最相关的。这是正在执行的相关计算。

In essence, if you're performing a calculation and the result is an irrational number or recurring decimal, then there will be rounding errors when that number is squashed into the finite size data structure you're using. Since double is twice the size of float then the rounding error will be a lot smaller.

本质上,如果您正在执行计算并且结果是无理数或重复的小数,那么当该数被压缩到您正在使用的有限大小数据结构中时,将存在舍入误差。由于double是float的两倍,因此舍入误差会小很多。

The tests may specifically use numbers which would cause this kind of error and therefore tested that you'd used the appropriate type in your code.

测试可能会专门使用会导致此类错误的数字,因此测试您在代码中使用了适当的类型。

#6


8  

Floats have less precision than doubles. Although you already know, read What WE Should Know About Floating-Point Arithmetic for better understanding.

浮点数的精度低于双精度数。虽然您已经知道,但请阅读我们应该了解的关于浮点运算的内容以便更好地理解。

#7


8  

Type float, 32 bits long, has a precision of 7 digits. While it may store values with very large or very small range (+/- 3.4 * 10^38 or * 10^-38), it has only 7 significant digits.

类型为float,长32位,精度为7位。虽然它可以存储非常大或非常小范围(+/- 3.4 * 10 ^ 38或* 10 ^ -38)的值,但它只有7位有效数字。

Type double, 64 bits long, has a bigger range (*10^+/-308) and 15 digits precision.

类型为double,64位长,具有更大的范围(* 10 ^ + / - 308)和15位精度。

Type long double is nominally 80 bits, though a given compiler/OS pairing may store it as 12-16 bytes for alignment purposes. The long double has an exponent that just ridiculously huge and should have 19 digits precision. Microsoft, in their infinite wisdom, limits long double to 8 bytes, the same as plain double.

类型long double名义上是80位,但是给定的编译器/ OS配对可以将其存储为12-16个字节以用于对齐目的。 long double有一个非常庞大的指数,应该有19位数的精度。微软凭借其无限的智慧,将长双倍限制为8字节,与普通双重相同。

Generally speaking, just use type double when you need a floating point value/variable. Literal floating point values used in expressions will be treated as doubles by default, and most of the math functions that return floating point values return doubles. You'll save yourself many headaches and typecastings if you just use double.

一般来说,只需在需要浮点值/变量时使用double类型。默认情况下,表达式中使用的文字浮点值将被视为双精度值,并且返回浮点值的大多数数学函数都会返回双精度值。如果你只使用双倍,你会省去许多头痛和类型。

#8


7  

I just ran into a error that took me forever to figure out and potentially can give you a good example of float precision.

我刚刚遇到一个错误,让我永远弄明白,并且可能会给你一个漂浮精度的好例子。

#include <iostream>#include <iomanip>int main(){  for(float t=0;t<1;t+=0.01){     std::cout << std::fixed << std::setprecision(6) << t << std::endl;  }}

The output is

输出是

0.0000000.0100000.0200000.0300000.0400000.0500000.0600000.0700000.0800000.0900000.1000000.1100000.1200000.1300000.1400000.1500000.1600000.1700000.1800000.1900000.2000000.2100000.2200000.2300000.2400000.2500000.2600000.2700000.2800000.2900000.3000000.3100000.3200000.3300000.3400000.3500000.3600000.3700000.3800000.3900000.4000000.4100000.4200000.4300000.4400000.4500000.4600000.4700000.4800000.4900000.5000000.5100000.5200000.5300000.5400000.5500000.5600000.5700000.5800000.5900000.6000000.6100000.6200000.6300000.6400000.6500000.6600000.6700000.6800000.6900000.7000000.7100000.7200000.7300000.7400000.7500000.7600000.7700000.7800000.7900000.8000000.8100000.8200000.8300000.8399990.8499990.8599990.8699990.8799990.8899990.8999990.9099990.9199990.9299990.9399990.9499990.9599990.9699990.9799990.9899990.999999

As you can see after 0.83, the precision runs down significantly.

正如您在0.83之后看到的那样,精度显着下降。

However, if I set up t as double, such an issue won't happen.

但是,如果我将t设置为double,则不会发生这样的问题。

It took me five hours to realize this minor error, which ruined my program.

我花了五个小时才意识到这个小错误,这毁了我的程序。

#9


3  

When using floating point numbers you cannot trust that your local tests will be exactly the same as the tests that are done on the server side. The environment and the compiler are probably different on you local system and where the final tests are run. I have seen this problem many times before in some TopCoder competitions especially if you try to compare two floating point numbers.

使用浮点数时,您不能相信您的本地测试将与服务器端的测试完全相同。环境和编译器可能与您本地系统和运行最终测试的位置不同。我之前在一些TopCoder比赛中已经多次看到这个问题,特别是如果你试图比较两个浮点数。

#10


2  

The built-in comparison operations differ as in when you compare 2 numbers with floating point, the difference in data type (i.e. float or double) may result in different outcomes.

内置比较操作的不同之处在于,当您将2个数字与浮点数进行比较时,数据类型的差异(即浮点数或双精度数)可能会导致不同的结果。

#11


-1  

Unlike an int (whole number), a float have a decimal point, and so can a double.But the difference between the two is that a double is twice as detailed as a float, meaning that it can have double the amount of numbers after the decimal point.

与int(整数)不同,float有一个小数点,所以double也可以。但是两者之间的区别在于double是float的两倍,这意味着它可以有两倍的数字。小数点。