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

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

เมธอด BitConverter.Int64BitsToDouble() ใน C# ใช้ตีความค่าจำนวนเต็ม 64 บิตที่มีเครื่องหมายใหม่เป็นตัวเลขจุดลอยตัวความแม่นยำคู่ (double)

ไวยากรณ์

public static double Int64BitsToDouble (long val);

พารามิเตอร์ val คือตัวเลขที่ต้องการแปลง

ตัวอย่าง

ตัวอย่างที่ 1: แปลง 9846587687 เป็น double

using System; 
public class Demo { 
    public static void Main(){ 
        long d = 9846587687; 
        Console.Write("Value (64-bit signed integer) = " + d); 
        double res = BitConverter.Int64BitsToDouble(d); 
        Console.Write("\nValue (double-precision floating point number) = " + res); 
    } 
}

ผลลัพธ์

Value (64-bit signed integer) = 9846587687 
Value (double-precision floating point number) = 4.86486070491012E-314

ตัวอย่างเพิ่มเติม

ตัวอย่างที่ 2: แปลง 20 เป็น double

using System; 
public class Demo { 
    public static void Main(){ 
        long d = 20; 
        Console.Write("Value (64-bit signed integer) = " + d); 
        double res = BitConverter.Int64BitsToDouble(d); 
        Console.Write("\nValue (double-precision floating point number) = " + res); 
    } 
}

ผลลัพธ์

Value (64-bit signed integer) = 20 
Value (double-precision floating point number) = 9.88131291682493E-323