Phương thức BitConverter.DoubleToInt64Bits() trong C# chuyển đổi số thực dấu phẩy động độ chính xác kép được chỉ định thành số nguyên có dấu 64-bit.
Cú pháp
public static long DoubleToInt64Bits(double val);
Tham số val là số cần chuyển đổi.
Ví dụ 1
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);
}
}
Đầu ra
Value = 5.646587687 64-bit signed integer = 4618043510978159912
Ví dụ 2
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);
}
}
Đầu ra
Value = 0.001 64-bit signed integer = 4562254508917369340