Changes

Jump to: navigation, search

Formatting Strings in C Sharp

1,160 bytes added, 16:19, 24 January 2008
The C# String.Format() Format Controls
<th>Control<th>Type<th>Description<th>Example</th>
<tr>
<td>C</td><td>Currency</td><td>Displays number prefixed with the currency simple appropriate to the current locale</td><td>{0:C} of 432.00 outputs $432.00</td>
<tr>
<td>D</td><td>Decimal</td><td>Displays number in decimal form with optional padding</td><td>{0:D4} of 432 outputs 00432</td>
<tr>
<td>E</td><td>Exponential</td><td>Displays number in scientific form with optional value for fractional part</td><td>{0:E5} of 432.32 outputs 4.32320E+002</td>
<tr>
<td>E</td><td>Fixed</td><td>Displays the number including the specified number of decimal digits</td><td>{0:F3} of 432.324343 outputs 432.324</td>
<tr>
<td>N</td><td>Number</td><td>Converts a number to a human friendly format by inserting commas and rounding to the nearest 100<sup>th</sup></td><td>{0:N} of 123432.324343 outputs 123,432.32</td>
<tr>
<td>X</td><td>Hexadecimal</td><td>Converts a number to hexadecimal</td><td>{0:X} of 432 outputs 1B0</td>
<tr>
<td>0:0...</td><td>Zero Padding</td><td>Adds zeros to pad argument</td><td>{0:0000.00} of 43.1 outputs 0043.10</td>
<tr>
<td>0:0#...</td><td>Space Padding</td><td>Adds spaces to pad argument</td><td>{0:####.##} of 43.1 outputs 43.1 </td>
<tr>
<td>%</td><td>Percentage</td><td>Multiplies the argument by 100 and appends a percentage sign</td><td>{0:00.00%} of .432 outputs 43.20%</td>
</table>

Navigation menu