使用Convert.ToInt64()方法在C#中将Decimal转换为Int64(长整数)。
假设我们有一个十进制变量。
decimal d = 310.23m;
现在要将其转换为Int64,请使用Convert.ToInt64()方法。
long res; res = Convert.ToInt64(d);
让我们看另一个例子-
using System; class Demo { static void Main() { decimal d = 190.66m; long res; res = Convert.ToInt64(d); Console.WriteLine("Converted Decimal '{0}' to Int64 value {1}", d, res); } }
输出结果
Converted Decimal '190.66' to Int64 value 191