我认为以这种格式声明和初始化浮点数是合法和传统的:
float someVariable = 12.502D; (or M, F does not give a compiler error).
Run Code Online (Sandbox Code Playgroud)
但是我收到编译器错误:
double类型的文字不能隐式转换为'float'类型; 使用'F'后缀来创建此类型的文字.
C#中有三种浮点数,对吧?
为了修复编译器错误,我明确地使用了赋值语句:
float SomeVariable = (float) 12.525D;
Run Code Online (Sandbox Code Playgroud)
在这种情况下我做对了吗?什么是传统或正确的方法来声明和初始化由Double或Decimal值组成的浮点变量?