Nitin Dhiman. Powered by Blogger.

.NET Standard Number Format Strings

No comments


.NET Standard Number Format Strings

Specifier

Name
Description
C or cCurrencyThe number is converted to a string that represents a currency amount. The conversion is controlled by the currency format information of the current NumberFormatInfo object. Precision specifier (eg. “{0:C5}” allowed.
D or dDecimalThis format is supported only for integral types. The number is converted to a string of decimal digits (0-9), prefixed by a minus sign if the number is negative. Precision specifier (eg. “{0:d3}” allowed.
E or eScientific
(expol)
The number is converted to a string of the form "-d.ddd…E+ddd" or "-d.ddd…e+ddd", where each 'd' indicates a digit (0-9). The string starts with a minus sign if the number is negative. One digit always precedes the decimal point. Precision specifier (eg. “{0:E5}” allowed. The case of the format specifier indicates whether to prefix the exponent with an 'E' or an 'e'. The exponent always consists of a plus or minus sign and a minimum of three digits. The exponent is padded with zeros to meet this minimum, if required.
F or fFixed-pointThe number is converted to a string of the form "-ddd.ddd…" where each 'd' indicates a digit (0-9). The string starts with a minus sign if the number is negative. Precision specifier (eg. “{0:f4}” allowed.
G or gGeneralThe number is converted to the most compact of either fixed-point or scientific notation, depending on the type of the number and whether a precision specifier is present.
N or nNumberThe number is converted to a string of the form "-d,ddd,ddd.ddd…", where '-' indicates a negative number symbol if required, 'd' indicates a digit (0-9), ',' indicates a thousand separator between number groups, and '.' indicates a decimal point symbol. The actual negative number pattern, number group size, thousand separator, and decimal separator are specified by the current NumberFormatInfo object. Precision specifier (eg. “{0:N5}” allowed.
P or pPercentThe number is converted to a string that represents a percent as defined by the NumberFormatInfo.PercentNegativePattern property if the number is negative, or the NumberFormatInfo.PercentPositivePattern property if the number is positive. The converted number is multiplied by 100 in order to be presented as a percentage. Precision specifier (eg. “{0:p6}” allowed.
R or rRound-tripThis format is supported only for the Single and Double types. The round-trip specifier guarantees that a numeric value converted to a string will be parsed back into the same numeric value. When a numeric value is formatted using this specifier, it is first tested using the general format, with 15 spaces of precision for a Double and 7 spaces of precision for a Single. If the value is successfully parsed back to the same numeric value, it is formatted using the general format specifier. However, if the value is not successfully parsed back to the same numeric value, then the value is formatted using 17 digits of precision for a Double and 9 digits of precision for a Single. Precision specifier NOT allowed.
X or xHexa
decimal
This format is supported only for integral types. The number is converted to a string of hexadecimal digits. The case of the format specifier indicates whether to use uppercase or lowercase characters for the hexadecimal digits greater than 9. Precision specifier (eg. "{0:x4}" allowed. If required, the number is padded with zeros to its left to produce the number of digits given by the precision specifier.
Any other single char.(Unknown specifier)An unknown specifier throws a runtime format exception.

No comments :

Post a Comment