在 C# 中将 Decimal 转换为 Int64 (long)
csharpprogrammingserver side programming更新于 2025/10/7 21:19:00
使用 Convert.ToInt64() 方法在 C# 中将 Decimal 转换为 Int64 (long)。
假设我们有一个十进制变量。
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

