在 C# 中將十進位制轉換為 Int64 (long)


使用 Convert.ToInt64() 方法在 C# 中將 Decimal 轉換為 Int64 (long)。

假設我們有一個十進位制變數。

decimal d = 310.23m;

現在使用 Convert.ToInt64() 方法,將它轉換為 Int64。

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

更新日期: 23-6 月-2020

7 千次瀏覽

開啟你的 職業生涯

完成課程獲得認證

開始
廣告
© . All rights reserved.