当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。