c# - VB6 到 C# : Hash Sign For Converting to Double

标签 c# type-conversion vb6-migration

我目前正在将 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/

相关文章:

c++ - 如何为 const char* 和 int 重载运算符 +

c - 将 C 字符串转换为所有一种情况处理器的最快方法

Java - char、int 转换

vb.net - 关闭后表单保留值

.net - COM 库的属性/方法描述

sql-server - SISS - 将 DT_STR 转换为 DT_DECIMAL 的问题(小数部分变为整数部分编号)

c# - 如何在紧凑的框架中记录操作?

c# - watin Attachto 嵌入式浏览器

c# - ubuntu中的Firefox浏览器检测

c# - 将c#的datetimepicker值存储到mysql数据库中