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

ค่าคงที่ทศนิยมใน C #


ประเภททศนิยมมีค่าคงที่เพื่อรับค่าต่ำสุดและสูงสุด

ตั้งค่าทศนิยม −

decimal d = 5.8M;

ในการรับค่าต่ำสุดและสูงสุดของประเภททศนิยม ให้ใช้คุณสมบัติดังต่อไปนี้ −

decimal.MaxValue
decimal.MinValue

นี่คือรหัสที่สมบูรณ์ -

ตัวอย่าง

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);
   }
}

ผลลัพธ์

5.8
Maximum Value: 79228162514264337593543950335
Maximum Value: -79228162514264337593543950335