เมธอด BitConverter.DoubleToInt64Bits() ใน C# ใช้แปลงตัวเลขจุดลอยตัวความแม่นยำคู่ (double) ที่ระบุเป็นจำนวนเต็ม 64 บิตที่มีเครื่องหมาย
ไวยากรณ์
public static long DoubleToInt64Bits (double val);
พารามิเตอร์ val คือตัวเลขที่ต้องการแปลง
ตัวอย่าง
ตัวอย่างที่ 1: แปลง 5.646587687 เป็น Int64
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
ตัวอย่างเพิ่มเติม
ตัวอย่างที่ 2: แปลง 0.001 เป็น Int64
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