Kiểu thập phân có các hằng số để nhận giá trị nhỏ nhất và lớn nhất.
Đặt giá trị thập phân -
decimal d = 5.8M;
Để nhận các giá trị nhỏ nhất và lớn nhất của kiểu thập phân, hãy sử dụng các thuộc tính sau -
decimal.MaxValue decimal.MinValue
Đây là mã hoàn chỉnh -
Ví dụ
using System;
using System.Linq;
class Demo {
static void Main() {
decimal d = 5.8M;
Console.WriteLine(d);
Console.WriteLine("Maximum Value: "+decimal.MaxValue);
Console.WriteLine("Maximum Value: "+decimal.MinValue);
}
} Đầu ra
5.8 Maximum Value: 79228162514264337593543950335 Maximum Value: -79228162514264337593543950335