Csharp/C Sharp/Development Class/NumberFormatInfo

Материал из .Net Framework эксперт
Перейти к: навигация, поиск

Set NumberGroupSeparator

using System.Globalization;
using System;
public class MainClass {
    public static void Main() {
        NumberFormatInfo f = new NumberFormatInfo();
        f.NumberGroupSeparator = " ";
        Console.WriteLine(12345.6789.ToString("N3", f));   // 12 345.679
    }
}


Use NumberFormatInfo to format a number

using System;
using System.Globalization;
public class MainClass {
    public static void Main() {
        NumberFormatInfo f = new NumberFormatInfo();
        f.CurrencySymbol = "$$";
        Console.WriteLine(3.ToString("C", f));          // $$ 3.00
    }
}