Developing .NET Enterprise Applications

This appendix shows you the string format specifiers you can use when developing enterprise applications using C#.

Formatting Numbers

A format specifier can quickly convert a numerical value into a properly formatted value string:

int i = 15; Console.WriteLine( "{0:c} [" + string.Format( "{0:c}", i ) + "]" );

Table C-1 describes how to format numbers that take an integer value of 15.

Table C-1: Formatting Numbers Taking an Integer Value of 15

SPECIFIER

TYPE

FORMAT

OUTPUT

c

Currency

{0:c}

$15.00

d

Whole number

{0:d}

15

e

Scientific

{0:e}

1.500000e+001

e

Formatted scientific

{0:00e+0}

15e+0

f

Fixed point

{0:f}

15

g

General

{0:g}

15

n

Number with commas for thousands

{0:n}

15.00

x

Hexadecimal

{0:x4}

000f

#

Digit placeholder

{0:(#).##}

(15)

.

Decimal point

{0:0.0}

15.0

,

Thousand separator

{0:0,0}

15

,.

Number scaling

{0:0,.}

%

Percent

{0:0%}

1500%

Категории