我目前正在将 VB6 项目转换为 C#,我注意到 VB6 允许您在计算期间在整数后面添加 #
以将其标记(并转换)为 double 。
示例:
If valueAsDeg >= (1# / 60#) Then Err.Raise - 1
在 C# 中是否有类似的方法来执行此操作?
最佳答案
使用后缀“D”,例如一维
By default, a real numeric literal on the right-hand side of the assignment operator is treated as double. However, if you want an integer number to be treated as double, use the suffix d or D.
http://msdn.microsoft.com/en-US/library/678hzkk9(v=vs.110).aspx
double result = 1 / 60;
Console.WriteLine( result );
输出:0
double result = 1D / 60D;
Console.WriteLine( result );
输出:0.0166666666666667
请注意,float
“F”、decimal
“M”和long
“L”也有类似的后缀,以及支持unsigned suffixes .
关于c# - VB6 到 C# : Hash Sign For Converting to Double,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15844833/