Dim var As Decimal = 12454545.340456
txt_messages.Text = var.ToString("N8") ' Where8 is the number of digits we want to display after decimal.
'////////////////
the Output is
12,454,545.34045600
In Output its clearly seen that our format specifier has inserted 2 0s to make the number of digits 8 after decimal AND also has inserted commas after Each Thousand.
----------------------------------------------------------------------------------
Further Format Specifier Details are following :
Trailing zeros after the decimal point are removed, and the resulting string contains a decimal point only if required. The resulting string uses fixed-point format if the exponent of the number (as produced by the 'E' format) is less than the number of significant digits, and greater than or equal to –4. Otherwise, the resulting string uses scientific format, and the case of the format specifier controls whether the format is prefixed with an 'E' or an 'e'.
Format specifer
Name
Description
C or c
Currency
The number is converted to a string that represents a currency amount. The conversion is controlled by the currency format information of the
D or d
Decimal
This format is supported for integral types only. The number is converted to a string of decimal digits (0-9), prefixed by a minus sign if the number is negative. The precision specifier indicates the minimum number of digits desired in the resulting string. If required, the number is padded with zeros to its left to produce the number of digits given by the precision specifier.
E or e
Scientific (exponential)
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. The precision specifier indicates the desired number of digits after the decimal point. If the precision specifier is omitted, a default of six digits after the decimal point is used. 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 f
Fixed-point
The 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. The precision specifier indicates the desired number of decimal places. If the precision specifier is omitted, the default numeric precision given by the NumberFormatInfo is used.
G or g
General
The number is converted to the most compact decimal form, using fixed or scientific notation. The precision specifier determines the number of significant digits in the resulting string. If the precision specifier is omitted, the number of significant digits is determined by the type of number being converted:
N or n
Number
The number is converted to a string of the form "-d,ddd,ddd.ddd…", where each 'd' indicates a digit (0-9). The string starts with a minus sign if the number is negative. Thousand separators are inserted between each group of three digits to the left of the decimal point. The precision specifier indicates the desired number of decimal places. If the precision specifier is omitted, the default numeric precision given by the NumberFormatInfo is used.
P or p
Percent
The number is converted to a string that represents a percent as defined by the
R or r
Round-trip
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, then it is formatted using the general format specifer. 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. Although a precision specifier can be appended to the round-trip format specifier, it is ignored. Round trips are given precedence over precision when using this specifier. This format is supported by floating-point types only.
X or x
Hexadecimal
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. For example, use 'X' to produce 'ABCDEF', and 'x' to produce 'abcdef'. The precision specifier indicates the minimum number of digits desired in the resulting string. If required, the number is padded with zeros to its left to produce the number of digits given by the precision specifier. This format is supported for integral types only.