當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


C# BitConverter.DoubleToInt64Bits()用法及代碼示例


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

參考:



相關用法


注:本文由純淨天空篩選整理自RohitPrasad3大神的英文原創作品 C# | BitConverter.DoubleToInt64Bits() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。