เมธอด Double.ToString() ใน C# ใช้แปลงค่าตัวเลขของอินสแตนซ์นี้เป็นการแสดงผลสตริงที่เทียบเท่า
ไวยากรณ์
public override string ToString ();
ตัวอย่าง
ตัวอย่างที่ 1: แปลงค่า double บวก
using System;
public class Demo{
public static void Main(){
double d = 45.7878d;
string str = d.ToString();
Console.WriteLine("String = " + str);
}
}
ผลลัพธ์
String = 45.7878
ตัวอย่างเพิ่มเติม
ตัวอย่างที่ 2: แปลงค่า double ลบ
using System;
public class Demo{
public static void Main(){
double d = -68.89d;
string str = d.ToString();
Console.WriteLine("String = " + str);
}
}
ผลลัพธ์
String = -68.89