在 C# 中將 Decimal 轉換為等效的 32 位無符號整數


要將指定 Decimal 的值轉換為等效的 32 位無符號整數,程式碼如下 −

示例

 線上演示

using System;
public class Demo {
   public static void Main() {
      Decimal val = 0.001m;
      Console.WriteLine("Decimal value = "+val);
      uint res = Decimal.ToUInt32(val);
      Console.WriteLine("32-bit unsigned integer = "+res);
   }
}

輸出

將生成以下輸出 −

Decimal value = 0.001
32-bit unsigned integer = 0

示例

我們來看另一個示例 −

 線上演示

using System;
public class Demo {
   public static void Main() {
      Decimal val = 67.487m;
      Console.WriteLine("Decimal value = "+val);
      uint res = Decimal.ToUInt32(val);
      Console.WriteLine("32-bit unsigned integer = "+res);
   }
}

輸出

將生成以下輸出 −

Decimal value = 67.487
32-bit unsigned integer = 67

更新時間:2019 年 12 月 11 日

367 次瀏覽

開啟你的 職業生涯

完成課程即可獲得認證

開始
廣告
© . All rights reserved.