【问题标题】:difference between float and double data typefloat 和 double 数据类型的区别
【发布时间】:2021-08-11 00:23:43
【问题描述】:

float变量如何存储在double变量中?

如何消除以下命令中的编译错误?

float numb;
numb = 22.54;

【问题讨论】:

  • 您可以通过附加“F”来表示浮点字面量:numb = 22.54F;
  • 您在研究该编译器错误时发现了什么?

标签: c# var


【解决方案1】:

float 和 double 有两个主要区别。这些是尺寸和精度。

Float - 7 位精度(32 位)和 4 个字节 例如:- 0.1234567

双精度 - 15 位精度(64 位)和 8 个字节 例如:- 0.123456789123456

您可以像这样将浮点值存储在双变量中

double numb;
float numb2 = 22.5F;
numb = numb2;

output -> 22.5

【讨论】:

  • You can store float variable in a double variable like this,不是double类型,是float....我相信你的意思是说,you can store a double in a float variable......
  • 是的,我的错。我确定了答案。
猜你喜欢
  • 2011-03-17
  • 1970-01-01
  • 1970-01-01
  • 2016-03-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-02-22
  • 1970-01-01
相关资源
最近更新 更多