What is toString(“X2”)?

“X2” here denotes the hexadecimal format specifier. Standard numeric format strings are used to format common numeric types. A standard format string takes the form Axx where A is a single alphabetic character called the format specifier, and xx is an optional integer called the precision specifier. The format specifier must be one of the built-in format characters. The precision specifier ranges from 0 to 99 and controls the number of significant digits or zeros to the right of a decimal. The format string cannot contain white spaces.

If the format string does not contain one of the standard format specifiers, then a FormatException is thrown. For example, the format string “z” is interpreted as a standard numeric format string because it contains one alphabetic character, but the alphabetic character is not one of the standard numeric format specifiers so a FormatException is thrown. Any numeric format string that does not fit the definition of a standard numeric format string is interpreted as a custom numeric format string. The format string “c!” is interpreted as a custom format string because it contains two alphabetic characters, even though the character “c” is a standard numeric format specifier.

The following table describes the standard numeric format strings. Note that the result string produced by these format specifiers is influenced by the settings in the Regional Options control panel. Computers using different settings will generate different result strings.

 

Please visit Custom Numeric Format Strings for more details.

Source: msdn.microsoft.com

 

 

1 thought on “What is toString(“X2”)?”

Leave a Comment