BitConverter.DoubleToInt64Bits(Double)方法用于将指定的双精度浮点数转换为64位带符号整数。
句法:
public static long DoubleToInt64Bits (double value);
在此,该值是要转换的数字。
返回值:该方法返回一个64位带符号整数,其值等于value 。
下面的程序说明了BitConverter.DoubleToInt64Bits(Double)方法的用法:
范例1:
// C# program to demonstrate
// BitConverter.DoubleToInt64Bits()
// Method
using System;
public class GFG {
// Main Method
public static void Main()
{
// declaring and initializing double value
double value = 1.2345678901234565;
// Display the double value
Console.Write("double-precision floating point: ");
Console.WriteLine("{0}", value);
Console.WriteLine();
// Converting double to long value
// using BitConverter.DoubleToInt64Bits()
// Method
long value1 = BitConverter.DoubleToInt64Bits(value);
// Display the 64-bit signed integer.
Console.Write("64-bit signed integer: ");
Console.WriteLine("{0}", value1);
}
}
输出:
double-precision floating point: 1.23456789012346
64-bit signed integer: 4608238818662570490
范例2:
// C# program to demonstrate
// BitConverter.DoubleToInt64Bits()
// Method
using System;
class GFG {
// Main Method
public static void Main()
{
// declaring and initializing double value
double value = 1.0;
// Display the double value
Console.Write("double-precision floating point: ");
Console.WriteLine("{0}", value);
Console.WriteLine();
// Converting double to long value
// using BitConverter.DoubleToInt64Bits()
// Method
long value1 = BitConverter.DoubleToInt64Bits(value);
// Display the 64-bit signed integer.
Console.Write("64-bit signed integer: ");
Console.WriteLine("{0}", value1);
Console.WriteLine();
// Display the Hexadecimal value
Console.Write("Hexadecimal value: ");
Console.WriteLine(value1.ToString("X"));
}
}
输出:
double-precision floating point: 1
64-bit signed integer: 4607182418800017408
Hexadecimal value: 3FF0000000000000
参考:
- https://docs.microsoft.com/zh-cn/dotnet/api/system.bitconverter.doubletoint64bits?view=netframework-4.7.2