Csharp/C Sharp/Development Class/NumberFormatInfo

Материал из .Net Framework эксперт
Версия от 14:43, 26 мая 2010; Admin (обсуждение | вклад) (1 версия)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

Set NumberGroupSeparator

<source lang="csharp"> 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
   }

}

      </source>


Use NumberFormatInfo to format a number

<source lang="csharp">

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
   }

}

      </source>