13.2. Number Formatting

Table 13.1 lists the format specifiers for number formatting. You can format numeric types using the ToString() method on the data types. The standard format specifier string consists of a special character followed by a sequence of digits specifying precision.

13.2.1. Currency Formatting

Listing 13.1 shows currency formatting. The format specifier to be used is C or c.

Listing 13.1. Currency Formatting (C#)
 using System; using System.Globalization; using System.IO; public class NumericFormatting { static float NUMBER = 334.456F; public static void Main(string[] args) { TextWriter tw = Console.Out; PlainCurrencyFormatting(tw); CurrencyFormattingWithCustomProvider(tw); GreatBritainCurrencyFormatting(tw); } private static ...

Get .NET for Java Developers: Migrating to C# now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.