要将指定的双精度浮点数转换为64位带符号整数,代码如下-
using System; public class Demo { public static void Main() { double d = 5.646587687; Console.Write("Value = "+d); long res = BitConverter.DoubleToInt64Bits(d); Console.Write("\n64-bit signed integer = "+res); } }
输出结果
这将产生以下输出-
Value = 5.646587687 64-bit signed integer = 4618043510978159912
让我们看另一个例子-
using System; public class Demo { public static void Main() { double d = 0.001; Console.Write("Value = "+d); long res = BitConverter.DoubleToInt64Bits(d); Console.Write("\n64-bit signed integer = "+res); } }
输出结果
这将产生以下输出-
Value = 0.001 64-bit signed integer = 4562254508917369340