Computer >> คอมพิวเตอร์ >  >> การเขียนโปรแกรม >> C#

BitConverter.DoubleToInt64Bits () เมธอดใน C #


BitConverter.DoubleToInt64Bits() ใน C# ใช้เพื่อแปลงเลขทศนิยมแบบ double-precision ที่ระบุให้เป็นจำนวนเต็ม 64 บิตที่มีเครื่องหมาย

ไวยากรณ์

ต่อไปนี้เป็นไวยากรณ์ -

public static long DoubleToInt64Bits (double val);

ด้านบน Val คือตัวเลขที่จะแปลง

ตัวอย่าง

ให้เราดูตัวอย่างการใช้วิธีการ BitConverter.DoubleToInt64Bits() -

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