NumberFormatInfo

NumberFormatInfo


Provides numeric formatting information.


Remarks


An instance of this class can be used to provide formatting for numeric data in places that allow for an IFormatProvider to be supplied. StringBuilder.AppendFormat is an example of when a NumberFormatInfo object can be used. Also, an instance of NumberFormatInfo can be used stand-alone to format numeric data by calling the Format method.

To format a number using NumberFormatInfo, call the Format method passing in the value to be formated.

This table is from the Microsoft Dot NET 1.1 MSDN.' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' '
Format CharacterDescription and Associated Properties
c, CCurrency format. CurrencyNegativePattern, CurrencyPositivePattern, CurrencySymbol, CurrencyGroupSizes, CurrencyGroupSeparator, CurrencyDecimalDigits, CurrencyDecimalSeparator.
d, DDecimal format.
e, EScientific (exponential) format.
f, FFixed-point format.
g, GGeneral format.
n, NNumber format. NumberNegativePattern, NumberGroupSizes, NumberGroupSeparator, NumberDecimalDigits, NumberDecimalSeparator.
x, XHexadecimal format.
'

'' This example shows how to format a value as a currency using'' the default formatting setting and a custom setting.Private Sub Main()    Dim f As New NumberFormatInfo        '' Display the value using the default currency formatting.    Console.WriteLine f.Format(123, "c")        '' Set a custom currency format.    f.CurrencySymbol = "$$"    f.CurrencyDecimalDigits = 4    f.CurrencyPositivePattern = [$ n]        '' Display the value using the custom currency formatting.    Console.WriteLine f.Format(123, "c")        '' Wait for user to press enter    Console.ReadLineEnd Sub'' This code produces the following output'''' 123.00'' $$ 123.0000

See Also

Project VBCorLib Overview | NumberFormatInfoStatic | IFormatProvider | ICloneable

Implements:

ICloneable 
IFormatProvider 
IObject 

Public:

Types:

NameDescription
 CurrencyNegativePatternsOutput patterns for negative currency values. The $ is the currency symbol, then - is the negative symbol and n is the number. 
 CurrencyPositivePatternsOutput patterns for positive currency values. The $ is the currency symbol and n is the number. 
 NumberNegativePatternsOutput patterns for negative numbers. 
 PercentNegativePatternsOutput patterns for negative percentage values. The - is the negative symbol, # is the number and the % is the percentage symbol. 
 PercentPositivePatternsOutput patterns for positive percentage values. The # is the number and the % is the percentage symbol. 

Properties:

NameDescription
 CurrencyDecimalDigits (get)Returns the default number of digits after the decimal separator. 
 CurrencyDecimalDigits (let)Sets the default number of digits to be shown after the decimal separator. 
 CurrencyDecimalSeparator (get)Returns the decimal separator used in formatting numbers into currency. 
 CurrencyDecimalSeparator (let)Sets the decimal separator used in formatting numbers into currency. 
 CurrencyGroupSeparator (get)Returns the string to be use as a group separator. 
 CurrencyGroupSeparator (let)Sets the group separator to be used when separating digits. 
 CurrencyGroupSizes (let)Sets an array of longs which represent a set of group sizes before being comma separated. 
 CurrencyGroupsSizes (get)Returns an array of longs which represent a comma separator group size. 
 CurrencyNegativePattern (get)The numeric pattern to be used when formatting negative values. 
 CurrencyNegativePattern (let)Sets the numeric pattern to be used when formatting negative values. 
 CurrencyPositivePattern (get)Returns the formatting pattern to be used for positive currency values. 
 CurrencyPositivePattern (let)Sets the formatting pattern to be used for positive currency values. 
 CurrencySymbol (get)Returns the currency symbol. 
 CurrencySymbol (let)Sets the currency symbol to be used. 
 IsReadOnly (get)Returns if this instance is read-only. 
 NaNSymbol (get)Returns the string representation for Not-A-Number. 
 NaNSymbol (let)Sets the string representation for Not-A-Number. 
 NegativeInfinitySymbol (get)Returns a string representation of negative infinty. 
 NegativeInfinitySymbol (let)Sets the negative infinity representation. 
 NegativeSign (get)Returns the negative symbol for negative numbers. 
 NegativeSign (let)Sets the negative symbol to be used for negative numbers. 
 NumberDecimalDigits (get)The default number of digits to be appended after the decimal point if one is used. 
 NumberDecimalDigits (let)Sets the default number of digits to be appended after the decimal point. 
 NumberDecimalSeparator (get)Returns the character used as a decimal point. 
 NumberDecimalSeparator (let)Sets the character to be used as the decimal point. 
 NumberGroupSeparator (get)Returns the separator character for groups of numbers. 
 NumberGroupSeparator (let)Sets the separator charactor for a group of numbers. 
 NumberGroupSizes (get)Returns the current group sizes array for formatted numbers. 
 NumberGroupSizes (let)Sets the group sizes for formatted numbers. 
 NumberNegativePattern (get)Returns the pattern to be used when formatting negative numbers. 
 NumberNegativePattern (let)Sets the pattern to be used when formatting negative numbers. 
 PercentDecimalDigits (get)Returns the number of digits to be displayed after the decimal point for percent formatted numbers. 
 PercentDecimalDigits (let)Sets the number of digits after the decimal point for percent formatted numbers. 
 PercentDecimalSeparator (get)Returns the decimal symbol for percent formatted numbers. 
 PercentDecimalSeparator (let)Sets the decimal symbol for percent formatted numbers. 
 PercentGroupSeparator (get)Returns the group separator for a percent formatted number. 
 PercentGroupSeparator (let)Sets the group separator for a percent formatted number. 
 PercentGroupSizes (let)Sets the group sizes for percent formatted numbers. 
 PercentGroupsSizes (get)Returns the current group sizes array for percent formatted numbers. 
 PercentNegativePattern (get)Returns the selected negative pattern used in percent number formatting. 
 PercentNegativePattern (let)Sets the negative pattern to be used in formatting negative percent numbers. 
 PercentPositivePattern (get)Returns the pattern to be used in formatting positive percent numbers. 
 PercentPositivePattern (let)Sets the pattern to be used in formatting positive percent numbers. 
 PercentSymbol (get)Returns the percent symbol used in percent formatted numbers. 
 PercentSymbol (let)Set the percent symbol used in percent formatted numbers. 
 PerMilleSymbol (get)Returns the permille representation. 
 PerMilleSymbol (let)Sets the permille representation. 
 PositiveInfinitySymbol (get)Returns a string representation of positive infinity. 
 PositiveInfinitySymbol (let)Sets the positive infinity representation. 
 PositiveSign (get)Returns the current positive symbol. 
 PositiveSign (let)Sets the positive symbol. 

Methods:

NameDescription
 CloneReturns a clone of this instance. 
 EqualsReturns a boolean indicating if the value and this object instance are the same instance. 
 formatFormat a numeric value with the proper formatting applied to the value type. Bytes, Integer, and Longs are formatted as Longs. singles and Doubles are formatted individually. 
 GetFormatReturns a format provider of the requested type. 
 GetHashCodeReturns a pseudo-unique number identifying this instance. 
 ToStringReturns a string representation of this object instance.