格式化输出

Character Description Examples Output

C or c

Currency

Console.Write("{0:C}", 2.5);

Console.Write("{0:C}", -2.5);

$2.50

($2.50)

D or d

Decimal

Console.Write("{0:D5}", 25);

00025

E or e

Scientific

Console.Write("{0:E}", 250000);

2.500000E+005

F or f

Fixed-point

Console.Write("{0:F2}", 25);

Console.Write("{0:F0}", 25);

25.00

25

G or g

General

Console.Write("{0:G}", 2.5);

2.5

N or n

Number

Console.Write("{0:N}", 2500000);

2,500,000.00

X or x

Hexadecimal

Console.Write("{0:X}", 250);

Console.Write("{0:X}", 0xffff);

FA

FFFF

posted @ 2007-02-27 17:34  ahuo  阅读(238)  评论(1编辑  收藏  举报