CSharp - Custom numeric format strings

Introduction

The following table lists the Custom numeric format strings

Specifier
Meaning
Sample input
Result
Notes
#

Digit
placeholder
12.345, ".##"
12.345, ".####"
12.35
12.345
Limits digits after D.P.

0


Zero
placeholder

12.345, ".00"
12.345, ".0000"
99, "000.00"
12.35
12.3450
099.00
As above, but also pads with
zeros before and after D.P.

.


Decimal point


.


.


Indicates D.P.
Actual symbol comes from
NumberFormatInfo
,



Group
separator


1234,
"#,###,###"
1234,
"0,000,000"
1,234
0,001,234


Symbol comes from Number
FormatInfo


,



Multiplier



1000000, "#,"
1000000, "#,,


1000
1


If comma is at end or before
D.P., it acts as a multiplier-
dividing result by 1,000,
1,000,000, etc.
%



Percent
notation


0.6, "00%"



60%



First multiplies by 100 and
then substitutes percent
symbol obtained from Num
berFormatInfo
E0, e0, E
+0, e+0
E-0, e-0

Exponent
notation


1234, "0E0"
1234, "0E+0"
1234, "0.00E00"
1234, "0.00e00"
1E3
1E+3
1.23E03
1.23e03
Scientific



\


Literal
character quote

50, @"\#0"


#50


Use in conjunction with an @
prefix on the string-or use
\\
'xx''xx'

Literal string
quote
50, "0 '...'"

50 ...

Your own string

;


Section
separator

15, "#;(#);zero"
-5, "#;(#);zero"
0, "#;(#);zero"
15
(5)
zero
(If positive)
(If negative)
(If zero)
Any other char
Literal
35.2, "$0 . 00c"
$35 . 20c
Literal