@@ -20,7 +20,7 @@ You can specify the direction to be left or right.
2020
2121The second syntax in composite formatting is a optional integer for the interpolation:
2222
23- - specify direction of padding by ` - ` (pad spaces on left) and pad on right by default
23+ - specify direction of padding by ` - ` (leave interpolated on left) and pad on right by default
2424- length of padding
2525
2626``` cs
@@ -51,5 +51,40 @@ string.Format("{0,-20}", 123);
5151 - supported for ` Double ` , ` Single ` , ` Half ` and ` BigInteger ` only.
5252 - ensures the converted string represents the exact precision of the number.
5353
54+ #### Arbitrary Format Composition
55+
56+ Composite formatting supports a dedicated syntax to represent any numeric format by following convention
57+
58+ - ` 0 ` to fill the unreached length
59+ - ` # ` to represent a single digit, does not fill up any or throw error when the ` # ` does not match the digits
60+ ``` cs
61+ double foo = 123 . 456 ;
62+ // shorter before decimal point and longer after
63+ // but still the same
64+ foo .ToString (" ##.#####################" ); // 123.456
65+ // rounded
66+ foo .ToString (" ###.##" ); // 123.46
67+ // if the format does not match the numeric(no decimal point here), will not preceed after
68+ foo .ToString (" ##,##" ); // 123
69+ ```
70+ - `.` to represent decimal point
71+ - `,` as group separator , real representation depends on `NumberFormatInfo .NumberGroupSeparator `, separated by `NumberFormatInfo .NumberGroupSizes `
72+ - `% ` multiply the numeric with 100 and convert it to localized string
73+ - `‰` multiply the numeric with 1000 and convert it to localized string
74+ - exponential format fits `[eE ][+-]? 0 + `, see : [documentation ](https :// learn.microsoft.com/en-us/dotnet/standard/base-types/custom-numeric-format-strings#the-e-and-e-custom-specifiers)
75+ - `;` to represent conditional solution for negative , zero and positive numeric within on format
76+ ```cs
77+ // first section for positive value
78+ // second section for negative value
79+ // third section for zero
80+ string fmt = " +#.#;-#.#;I am zero" ;
81+ 123 .ToString (fmt ); // +123
82+ (- 123 ).ToString (fmt ); // -123
83+ 0 .ToString (fmt ); // I am zero
84+ ```
85+ - `\` to escape any special character above
5486
5587## `ToString` & `IFormattable`
88+
89+
90+ ## Formatting Strategy
0 commit comments