Custom format specifier "." thêm dấu phân cách thập phân bản địa hóa vào chuỗi kết quả.
Dấu chấm đầu tiên trong chuỗi định dạng xác định vị trí dấu phân cách thập phân trong giá trị được định dạng.
double d = 2.3;
d.ToString("0.00", CultureInfo.InvariantCulture
Hãy xem ví dụ khác để học cách triển khai custom specifier ".".
Ví dụ
using System;
using System.Globalization;
class Demo {
static void Main() {
double d;
d = 3.7;
Console.WriteLine(d.ToString("0.00", CultureInfo.InvariantCulture));
Console.WriteLine(String.Format(CultureInfo.InvariantCulture, "{0:0.00}", d));
d = 5.89;
Console.WriteLine(d.ToString("00.00", CultureInfo.InvariantCulture));
Console.WriteLine(String.Format(CultureInfo.InvariantCulture, "{0:00.00}", d));
}
}
Kết quả
3.70 3.70 05.89 05.89