0% found this document useful (0 votes)
5 views

complete-reference-vb_net_22

Uploaded by

khalid
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

complete-reference-vb_net_22

Uploaded by

khalid
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

NumberFormatInfo

The key format providers that implement the IFormatProvider interface are listed as follows:

• NumberFormatInfo Formatting information for numeric data types


• DateTimeFormatInfo Formatting information for DateTime objects
• CultureInfo Formatting information for different cultures

In cases where formatting information is needed but no IFormatProvider is supplied, the CultureInfo object
associated with the current thread is usually used.

NumberFormatInfo

The standard NumberFormatInfo String comprises a character that represents the format, such as currency
or decimal, followed by digits that represent the precision. Table 15−4 lists the standard formats supported by
the Format method.

Currency

The Currency formatter is used to convert the given numerical value to a currency value. The currency value
can contain a locale−specific currency amount. The format information is determined by the current locale,
but you can override this by passing in the NumberFormatInfo object as an argument. The default in the
United States is, of course, USD. For example:

Console.WriteLine("{0:c}", 1250.99)
Console.WriteLine("{0:c}", −1250.99)

Tip The Console.WriteLine method automatically calls String.Format as demonstrated in the preceding and
following examples (as does ToString if the argument can be formatted as defined by the IFormattable
interface).
Table 15−4: The Built−in Formatters, or Format Providers, that Implement IFormatProvider

Format Specifier Output


C, c Currency
D, d Decimal
E, e Exponential (scientific)
F, f Fixed−point
G, g General
N, n Number
R, r Roundtrip. This format ensures that numbers converted to Strings will get
the same value when they are converted back to numbers.
X, x Hexadecimal
The output to the console is the following:

$1,250.99
($1,250.99)

506

You might also like