將指定雙精度浮點數轉換為 C# 中的 64 位有符號整數


要把指定雙精度浮點數轉換為 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("
64-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("
64-bit signed integer = "+res);    } }

輸出

將輸出以下內容 -

Value = 0.001
64-bit signed integer = 4562254508917369340

更新於: 11-12-2019

319 次瀏覽

開啟你的 職業發展

透過完成課程獲取認證

開始
廣告
© . All rights reserved.