在初始化“float”时,转换为“float”并添加“f”作为后缀,有什么区别? [英] What is the difference between casting to `float` and adding `f` as a suffix when initializing a `float`?
本文介绍了在初始化“float”时,转换为“float”并添加“f”作为后缀,有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
What is the difference between
float f = (float) 99.32 ;
和
float f = 99.32f ;
它们都编译成功并运行。
Both of them compiled and ran successfully.
推荐答案
float f = 99.32f ;
这是一个 float
字面值,意思是一个浮点型变量被直接赋值为 float
值。
That is a float
literal, which means a float variable being assigned with a float
value directly.
float f = (float) 99.32 ;
这是一个被赋值的 float
变量一个 double
值被分配给 float
。
That is a float
variable that is assigned a double
value that is casted to float
before being assigned.
这篇关于在初始化“float”时,转换为“float”并添加“f”作为后缀,有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文