C# Program to convert a Double value to an Int64 value

CsharpProgrammingServer Side Programming

To convert a Double value to an Int64 value, use the Convert.ToInt64() method.

Int64 represents a 64-bit signed integer.

Let’s say the following is our double value.

double val = 23.951213e12;

Now to convert it to Int64.

long longVal = Convert.ToInt64(val);

Let us see the complete example.

Example

 Live Demo

using System;
public class Demo {
   public static void Main() {
      double val = 23.951213e12;
      long longVal = Convert.ToInt64(val);
      Console.WriteLine("Converted double {0:E} to Int64 {1:N0} value ", val, longVal);
   }
}

Output

Converted double 2.395121E+013 to Int64 23,951,213,000,000 value
raja
Updated on 23-Jun-2020 08:47:13

Advertisements