C# में Decimal.ToInt64() मेथड का उपयोग निर्दिष्ट Decimal के मान को समतुल्य 64-बिट साइन्ड पूर्णांक में बदलने के लिए किया जाता है।
सिंटैक्स
निम्नलिखित सिंटैक्स है:
public static long ToInt64 (decimal val);
यहाँ, val परिवर्तित करने के लिए दशमलव संख्या है।
उदाहरण
आइए अब Decimal.ToInt64() मेथड को लागू करने का एक उदाहरण देखें:
using System;
public class Demo {
public static void Main(){
Decimal val1 = -567.7989m;
Decimal val2 = 456.000m;
Console.WriteLine("Decimal 1 = " + val1);
Console.WriteLine("Decimal 2 = " + val2);
long res1 = Decimal.ToInt64(val1);
long res2 = Decimal.ToInt64(val2);
Console.WriteLine("64-bit signed integer (value1) (Decimal to signed integer) = " + res1);
Console.WriteLine("64-bit signed integer (value1) (Decimal to signed integer) = " + res2);
}
}
आउटपुट
यह निम्नलिखित आउटपुट उत्पन्न करेगा:
Decimal 1 = -567.7989 Decimal 2 = 456.000 64-bit signed integer (value1) (Decimal to signed integer) = -567 64-bit signed integer (value1) (Decimal to signed integer) = 456
उदाहरण
आइए अब Decimal.ToInt64() मेथड को लागू करने का एक और उदाहरण देखें:
using System;
public class Demo {
public static void Main(){
Decimal val1 = 1.00m;
Decimal val2 = 34.678m;
Console.WriteLine("Decimal 1 = " + val1);
Console.WriteLine("Decimal 2 = " + val2);
long res1 = Decimal.ToInt64(val1);
long res2 = Decimal.ToInt64(val2);
Console.WriteLine("64-bit signed integer (value1) (Decimal to signed integer) = " + res1);
Console.WriteLine("64-bit signed integer (value1) (Decimal to signed integer) = " + res2);
}
}
आउटपुट
यह निम्नलिखित आउटपुट उत्पन्न करेगा:
Decimal 1 = 1.00 Decimal 2 = 34.678 64-bit signed integer (value1) (Decimal to signed integer) = 1 64-bit signed integer (value1) (Decimal to signed integer) = 34