Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> C#

การแปลงนัยโดยนัยจาก Int32 เป็น Decimal ใน C#

ประเภท int แทนจำนวนเต็ม 32 บิต ที่มีเครื่องหมาย คือ Int32

เพื่อแปลงนัยโดยนัย Int32 เป็น Decimal ขั้นแรกให้กำหนดค่า Int32:

int val = 392;

เพื่อแปลง Int32 เป็น decimal ให้กำหนดค่า:

decimal d; d = val;

มาดูตัวอย่างอีกตัวหนึ่ง

ตัวอย่าง

using System;

public class Demo
{
    public static void Main()
    {
        int val = 767;
        decimal d;
        Console.WriteLine("Implicit conversion from Int32 (integer) to Decimal");
        d = val;
        Console.WriteLine("Decimal : " + dec);
    }
}

ผลลัพธ์

Implicit conversion from Int32 (integer) to Decimal
Decimal : 767