Convert the specified double-precision floating point number to a 64-bit signed integer in C#

CsharpServer Side ProgrammingProgramming

To convert the specified double-precision floating point number to a 64-bit signed integer, the code is as follows −

Example

 Live Demo

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);
   }
}

Output

This will produce the following output −

Value = 5.646587687
64-bit signed integer = 4618043510978159912

Example

Let us see another example −

 Live Demo

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);
   }
}

Output

This will produce the following output −

Value = 0.001
64-bit signed integer = 4562254508917369340
raja
Published on 11-Dec-2019 07:18:27
Advertisements