Show / Hide Table of Contents

Class NumericFormats

This class defines standard numeric format strings, for use with the string.format method and its derivatives and relatives.

Inheritance
System.Object
NumericFormats
Inherited Members
System.Object.ToString()
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
Namespace: WizardWrx
Assembly: WizardWrx.Common.dll
Syntax
public static class NumericFormats

Fields

| Improve this Doc View Source

CURRENCY

Currency, which obeys the Regional Settings for currency, including the currency symbol and number of decimal places to show.

The negative sign comes from the regional settings, and leads the string, and the precision applies to the number of decimal (fraction) digits.

Declaration
public const string CURRENCY = "C"
Field Value
Type Description
System.String
See Also
https://msdn.microsoft.com/en-us/library/dwhawy9k(v=vs.100).aspx
| Improve this Doc View Source

DECIMAL

Decimal, which the documentation says is supported only for integral types. They mean business; if you try to use this type with a decimal or floating point number, you get an exception.

If the number requires fewer than the specified minimum number of digits, it is padded on the left with zeros, and there are no thousands separators.

The negative sign comes from the regional settings, and leads the string, and the precision applies to the number of digits to the left of the implied decimal point.

Declaration
public const string DECIMAL = "D"
Field Value
Type Description
System.String
See Also
https://msdn.microsoft.com/en-us/library/dwhawy9k(v=vs.100).aspx
| Improve this Doc View Source

DECIMAL_DIGITS_DEFAULT

For some applications, such as the static methods of this class, we set our own default number of decimal places, rather than relying on the Regional Settings (Locale), which can be changed, at any time, by any user, even with restricted permissions.

Format StringGenerator RoutineWidth Override
DECIMALFixedWidthIntegerint pintTotalDigits
FIXEDFixedPointDecimalint pintFractionDigits
GENERALGeneralXPrecisionint pintPrecisionDigits [1]
HEXADECIMALHexadecimalIntegerint pintTotalDigits
NUMBER_PER_REG_SETTINGSIntegerPerRegSettingsN /A
NUMBER_PER_REG_SETTINGSNumberPerRegSettingsint pintFractionDigits
PERCENTPercentToDecimalPlacesint pintFractionDigits
Note 1: There is only one of these methods, and it accepts the pintTotalDigits argument.
Declaration
public const int DECIMAL_DIGITS_DEFAULT = 2
Field Value
Type Description
System.Int32
See Also
DECIMAL_DIGITS_MIN
DECIMAL_DIGITS_MAX
DECIMAL_DIGITS_NONE
| Improve this Doc View Source

DECIMAL_DIGITS_MAX

The static format string generator methods in this class test the requested number of decimal points against this upper limit.

If the specified number is greater than this value, the methods behave as if the default had been specified.

Declaration
public const int DECIMAL_DIGITS_MAX = 99
Field Value
Type Description
System.Int32
See Also
DECIMAL_DIGITS_DEFAULT
DECIMAL_DIGITS_MIN
DECIMAL_DIGITS_NONE
| Improve this Doc View Source

DECIMAL_DIGITS_MIN

The static format string generator methods in this class test the requested number of decimal points against this lower limit.

If the specified number is less than this value, the methods behave as if the default had been specified.

Declaration
public const int DECIMAL_DIGITS_MIN = 0
Field Value
Type Description
System.Int32
See Also
DECIMAL_DIGITS_DEFAULT
DECIMAL_DIGITS_MAX
| Improve this Doc View Source

DECIMAL_DIGITS_NONE

This is a synonym of DECIMAL_DIGITS_MIN.

Declaration
public const int DECIMAL_DIGITS_NONE = 0
Field Value
Type Description
System.Int32
| Improve this Doc View Source

FIXED

This is the minimal fixed point format string. Modifiers can be appended to it to specify significant digits after the decimal point.

The negative sign comes from the regional settings, and leads the string, and the precision applies to the number of decimal (fraction) digits.

To specify the number of places to print after the decimal point, use the static FixedPointDecimal ( int pintFractionDigits ) method, which supports any number between zero and ninety-nine, the limits imposed by the framework.

Declaration
public const string FIXED = "F"
Field Value
Type Description
System.String
See Also
https://msdn.microsoft.com/en-us/library/dwhawy9k(v=vs.100).aspx
FIXED_2
FIXED_3
| Improve this Doc View Source

FIXED_2

This gives fixed point, with 2 places to the right of the decimal point, and without thousands separators.

Declaration
public const string FIXED_2 = "F2"
Field Value
Type Description
System.String
See Also
https://msdn.microsoft.com/en-us/library/dwhawy9k(v=vs.100).aspx
FIXED
FIXED_3
FixedPointDecimal()
FixedPointDecimal(Int32)
| Improve this Doc View Source

FIXED_3

This gives fixed point, with 3 places to the right of the decimal point, and without thousands separators.

Declaration
public const string FIXED_3 = "F3"
Field Value
Type Description
System.String
See Also
https://msdn.microsoft.com/en-us/library/dwhawy9k(v=vs.100).aspx
FIXED
FIXED_2
FixedPointDecimal()
FixedPointDecimal(Int32)
| Improve this Doc View Source

GENERAL_LC

This is the default, and it's pretty minimal. The documentation states that the number is converted to the most compact format.

When the size of the number and the specified precision dictate use of scientific notation, the exponential symbol is lower case; this is the only difference between this format and GENERAL_UC.

When the specified number of places after the decimal point is zero, the decimal point is omitted.

To easily specify the desired minimum number of hexadecimal glyphs, along with any of the prefixes and suffixes defined in this set of HEXADECIMAL_* constants, call static method IntegerToHexStr ( [T] , int pintTotalDigits , HexFormatDecoration penmDecoration ), in lieu of calling ToString on the integer.

Declaration
public const string GENERAL_LC = "g"
Field Value
Type Description
System.String
See Also
https://msdn.microsoft.com/en-us/library/dwhawy9k(v=vs.100).aspx
| Improve this Doc View Source

GENERAL_UC

This is the default, and it's pretty minimal, as it must be, since its status as the default means that it is the only format that supports all data types (numbers, dates, times, time spans, and all the rest. It is also among the few that render output left aligned.

The documentation states that the number is converted to the most compact format.

When the size of the number and the specified precision dictate use of scientific notation, the exponential symbol is UPPER case; this is the only difference between this format and GENERAL_LC.

When the specified number of places after the decimal point is zero, the decimal point is omitted.

To easily specify the desired minimum number of hexadecimal glyphs, along with any of the prefixes and suffixes defined in this set of HEXADECIMAL_* constants, call static method IntegerToHexStr ( [T] , int pintTotalDigits , HexFormatDecoration penmDecoration ), in lieu of calling ToString on the integer.

Declaration
public const string GENERAL_UC = "G"
Field Value
Type Description
System.String
See Also
https://msdn.microsoft.com/en-us/library/dwhawy9k(v=vs.100).aspx
| Improve this Doc View Source

HEXADECIMAL_16

Hexadecimal, which the documentation says is supported only for integral types. They mean business; if you try to use this type with a decimal or floating point number, you get an exception.

This format yields a result containing a minimum of 16 hexadecimal numerals. If the number needs more than 16 numerals, the returned string contains the minimum number of hexadecimal numerals required to represent the integer.

Use this format to represent long integer values, such as file sizes and 64 bit masks.

To easily specify the desired minimum number of hexadecimal glyphs, along with any of the prefixes and suffixes defined in this set of HEXADECIMAL_* constants, call static method IntegerToHexStr ( [T] , int pintTotalDigits , HexFormatDecoration penmDecoration ), in lieu of calling ToString on the integer.

Declaration
public const string HEXADECIMAL_16 = "X16"
Field Value
Type Description
System.String
| Improve this Doc View Source

HEXADECIMAL_2

Use this string as your argument to the ToString method of any integral data type to format it in hexadecimal notation, which the documentation says is supported only for integral types. They mean business; if you try to use this type with a decimal or floating point number, you get an FormatException exception.

This format yields a result containing a minimum of two hexadecimal numerals. If the number needs more than two numerals, the returned string contains the minimum number of hexadecimal numerals required to represent the integer.

To easily specify the desired minimum number of hexadecimal glyphs, along with any of the prefixes and suffixes defined in this set of HEXADECIMAL_* constants, call static method IntegerToHexStr ( [T] , int pintTotalDigits , HexFormatDecoration penmDecoration ), in lieu of calling ToString on the integer.

Declaration
public const string HEXADECIMAL_2 = "X2"
Field Value
Type Description
System.String
See Also
https://msdn.microsoft.com/en-us/library/dwhawy9k(v=vs.100).aspx
HEXADECIMAL_UC
HEXADECIMAL_4
HEXADECIMAL_8
HEXADECIMAL_16
HEXADECIMAL_PREFIX_0H_LC
HEXADECIMAL_PREFIX_0H_UC
HEXADECIMAL_PREFIX_0X_LC
HEXADECIMAL_PREFIX_0X_UC
| Improve this Doc View Source

HEXADECIMAL_4

Hexadecimal, which the documentation says is supported only for integral types. They mean business; if you try to use this type with a decimal or floating point number, you get an exception.

This format yields a result containing a minimum of four hexadecimal numerals. If the number needs more than two numerals, the returned string contains the minimum number of hexadecimal numerals required to represent the integer.

To easily specify the desired minimum number of hexadecimal glyphs, along with any of the prefixes and suffixes defined in this set of HEXADECIMAL_* constants, call static method IntegerToHexStr ( [T] , int pintTotalDigits , HexFormatDecoration penmDecoration ), in lieu of calling ToString on the integer.

Declaration
public const string HEXADECIMAL_4 = "X4"
Field Value
Type Description
System.String
See Also
https://msdn.microsoft.com/en-us/library/dwhawy9k(v=vs.100).aspx
HEXADECIMAL_UC
HEXADECIMAL_2
HEXADECIMAL_8
HEXADECIMAL_16
HEXADECIMAL_PREFIX_0H_LC
HEXADECIMAL_PREFIX_0H_UC
HEXADECIMAL_PREFIX_0X_LC
HEXADECIMAL_PREFIX_0X_UC
| Improve this Doc View Source

HEXADECIMAL_8

Hexadecimal, which the documentation says is supported only for integral types. They mean business; if you try to use this type with a decimal or floating point number, you get an exception.

This format yields a result containing a minimum of 8 hexadecimal numerals. If the number needs more than two numerals, the returned string contains the minimum number of hexadecimal numerals required to represent the integer.

Use this format to represent result codes returned by Windows DLLs and other such functions that return things such as HRESULTs.

To easily specify the desired minimum number of hexadecimal glyphs, along with any of the prefixes and suffixes defined in this set of HEXADECIMAL_* constants, call static method IntegerToHexStr ( [T] , int pintTotalDigits , HexFormatDecoration penmDecoration ), in lieu of calling ToString on the integer.

Declaration
public const string HEXADECIMAL_8 = "X8"
Field Value
Type Description
System.String
See Also
https://msdn.microsoft.com/en-us/library/dwhawy9k(v=vs.100).aspx
HEXADECIMAL_UC
HEXADECIMAL_2
HEXADECIMAL_4
HEXADECIMAL_16
HEXADECIMAL_PREFIX_0H_LC
HEXADECIMAL_PREFIX_0H_UC
HEXADECIMAL_PREFIX_0X_LC
HEXADECIMAL_PREFIX_0X_UC
| Improve this Doc View Source

HEXADECIMAL_LC

Use this string as your argument to the ToString method of any integral data type to format it in hexadecimal notation, which the documentation says is supported only for integral types. They mean business; if you try to use this type with a decimal or floating point number, you get an FormatException exception.

This format yields a result containing the fewest hexadecimal glyphs required to represent the number. The difference between this token and HEXADECIMAL_LC is that this token causes the returned string to contain UPPER case glyphs, while HEXADECIMAL_LC yields lower case glyphs.

To easily specify the desired minimum number of hexadecimal glyphs, along with any of the prefixes and suffixes defined in this set of HEXADECIMAL_* constants, call static method IntegerToHexStr ( [T] , int pintTotalDigits , HexFormatDecoration penmDecoration ), in lieu of calling ToString on the integer.

Declaration
public const string HEXADECIMAL_LC = "x"
Field Value
Type Description
System.String
See Also
HEXADECIMAL_UC
HEXADECIMAL_2
HEXADECIMAL_4
HEXADECIMAL_8
HEXADECIMAL_PREFIX_0H_LC
HEXADECIMAL_PREFIX_0H_UC
HEXADECIMAL_PREFIX_0X_LC
HEXADECIMAL_PREFIX_0X_UC
https://msdn.microsoft.com/en-us/library/dwhawy9k(v=vs.100).aspx
| Improve this Doc View Source

HEXADECIMAL_PREFIX_0H_LC

Not strictly a format string, this string is intended for use as a prefix for the string returned from a call to ToString with any of the HEXADECIMAL format strings.

To easily specify the desired minimum number of hexadecimal glyphs, along with any of the prefixes and suffixes defined in this set of HEXADECIMAL_* constants, call static method IntegerToHexStr ( [T] , int pintTotalDigits , HexFormatDecoration penmDecoration ), in lieu of calling ToString on the integer.

Declaration
public const string HEXADECIMAL_PREFIX_0H_LC = "0h"
Field Value
Type Description
System.String
| Improve this Doc View Source

HEXADECIMAL_PREFIX_0H_UC

Not strictly a format string, this string is intended for use as a prefix for the string returned from a call to ToString with any of the HEXADECIMAL format strings.

To easily specify the desired minimum number of hexadecimal glyphs, along with any of the prefixes and suffixes defined in this set of HEXADECIMAL_* constants, call static method IntegerToHexStr ( [T] , int pintTotalDigits , HexFormatDecoration penmDecoration ), in lieu of calling ToString on the integer.

Declaration
public const string HEXADECIMAL_PREFIX_0H_UC = "0H"
Field Value
Type Description
System.String
| Improve this Doc View Source

HEXADECIMAL_PREFIX_0X_LC

Not strictly a format string, this string is intended for use as a prefix for the string returned from a call to ToString with any of the HEXADECIMAL format strings.

To easily specify the desired minimum number of hexadecimal glyphs, along with any of the prefixes and suffixes defined in this set of HEXADECIMAL_* constants, call static method IntegerToHexStr ( [T] , int pintTotalDigits , HexFormatDecoration penmDecoration ), in lieu of calling ToString on the integer.

Declaration
public const string HEXADECIMAL_PREFIX_0X_LC = "0x"
Field Value
Type Description
System.String
| Improve this Doc View Source

HEXADECIMAL_PREFIX_0X_UC

Not strictly a format string, this string is intended for use as a prefix for the string returned from a call to ToString with any of the HEXADECIMAL format strings.

To easily specify the desired minimum number of hexadecimal glyphs, along with any of the prefixes and suffixes defined in this set of HEXADECIMAL_* constants, call static method IntegerToHexStr ( [T] , int pintTotalDigits , HexFormatDecoration penmDecoration ), in lieu of calling ToString on the integer.

Declaration
public const string HEXADECIMAL_PREFIX_0X_UC = "0X"
Field Value
Type Description
System.String
| Improve this Doc View Source

HEXADECIMAL_SUFFIX_H_LC

Not strictly a format string, this string is intended for use as a suffix for the string returned from a call to ToString with any of the HEXADECIMAL format strings.

To easily specify the desired minimum number of hexadecimal glyphs, along with any of the prefixes and suffixes defined in this set of HEXADECIMAL_* constants, call static method IntegerToHexStr ( [T] , int pintTotalDigits , HexFormatDecoration penmDecoration ), in lieu of calling ToString on the integer.

Declaration
public const string HEXADECIMAL_SUFFIX_H_LC = "h"
Field Value
Type Description
System.String
| Improve this Doc View Source

HEXADECIMAL_SUFFIX_H_UC

Not strictly a format string, this string is intended for use as a suffix for the string returned from a call to ToString with any of the HEXADECIMAL format strings.

To easily specify the desired minimum number of hexadecimal glyphs, along with any of the prefixes and suffixes defined in this set of HEXADECIMAL_* constants, call static method IntegerToHexStr ( [T] , int pintTotalDigits , HexFormatDecoration penmDecoration ), in lieu of calling ToString on the integer.

Declaration
public const string HEXADECIMAL_SUFFIX_H_UC = "H"
Field Value
Type Description
System.String
| Improve this Doc View Source

HEXADECIMAL_UC

Use this string as your argument to the ToString method of any integral data type to format it in hexadecimal notation, which the documentation says is supported only for integral types. They mean business; if you try to use this type with a decimal or floating point number, you get an FormatException exception.

This format yields a result containing the fewest hexadecimal glyphs required to represent the number. The difference between this token and HEXADECIMAL_LC is that this token causes the returned string to contain UPPER case glyphs, while HEXADECIMAL_LC yields lower case glyphs.

To easily specify the desired minimum number of hexadecimal glyphs, along with any of the prefixes and suffixes defined in this set of HEXADECIMAL_* constants, call static method IntegerToHexStr ( [T] , int pintTotalDigits , HexFormatDecoration penmDecoration ), in lieu of calling ToString on the integer.

Declaration
public const string HEXADECIMAL_UC = "X"
Field Value
Type Description
System.String
See Also
HEXADECIMAL_LC
HEXADECIMAL_2
HEXADECIMAL_4
HEXADECIMAL_8
HEXADECIMAL_16
HEXADECIMAL_PREFIX_0H_LC
HEXADECIMAL_PREFIX_0H_UC
HEXADECIMAL_PREFIX_0X_LC
HEXADECIMAL_PREFIX_0X_UC
https://msdn.microsoft.com/en-us/library/dwhawy9k(v=vs.100).aspx
| Improve this Doc View Source

INTEGER_PER_REG_SETTINGS

Format an integer per the Regional Settings in the Windows Control Panel. Sine this string is intended exclusively for formatting an Integer, it overrides the default regional settings value for Number of Digits After Decimal. Please see the Remarks for additional details.

Declaration
public const string INTEGER_PER_REG_SETTINGS = "N0"
Field Value
Type Description
System.String
Remarks

Since this string is intended exclusively for formatting an Integer, it overrides the default regional settings value, which is the value reported when GetLocaleInfo is called with its LCType argument set to LOCALE_IDIGITS (0x00000011, per WinNLS.h), which lives at HKEY_CURRENT_USER\Control Panel\International[iDigits] in the Windows Registry, and corresponds to the "No. of digits after decimal" property shown on the Numbers tab displayed by the Additional Settings button on the Region and Language Windows Control Panel applet dialog box.

See Also
NUMBER_PER_REG_SETTINGS_0D
| Improve this Doc View Source

NUMBER_PER_REG_SETTINGS

Format a number (any numeric type), using the Regional Settings (Locale) defaults for thousands separator, decimal symbol, number of decimal (fraction) places, and number of digits to display between each thousands separator.

Use this string as your argument to the ToString method of any numeric data type to format it in decimal notation, with zero or more places after the decimal point.

When the specified number of places after the decimal point is zero, the decimal point is omitted.

To specify the number of places to print after the decimal point, use the static NumberPerRegSettings ( int pintFractionDigits ) method, which supports any number between zero and ninety-nine, the limits imposed by the Base Class Library.

A shortcut to get an integer formatted is IntegerPerRegSettings.

Declaration
public const string NUMBER_PER_REG_SETTINGS = "N"
Field Value
Type Description
System.String
See Also
https://msdn.microsoft.com/en-us/library/dwhawy9k(v=vs.100).aspx
NUMBER_PER_REG_SETTINGS_0D
NUMBER_PER_REG_SETTINGS_2D
NUMBER_PER_REG_SETTINGS_3D
| Improve this Doc View Source

NUMBER_PER_REG_SETTINGS_0D

Feed this string to the ToString method of any numeric value to format it according to the Regional Settings (Locale) defaults for thousands separator, decimal symbol, and number of digits to display between each thousands separator.

In contrast to NUMBER_PER_REG_SETTINGS, this string overrides the default decimal places value, and always displays ZERO digits to the right of the decimal point.

To specify the number of places to print after the decimal point, use the static NumberPerRegSettings ( int pintFractionDigits ) method, which supports any number between zero and ninety-nine, the limits imposed by the Base Class Library.

A shortcut to get an integer formatted is IntegerPerRegSettings, and an alias, which avoids the overhead of a method call, is INTEGER_PER_REG_SETTINGS.

Declaration
public const string NUMBER_PER_REG_SETTINGS_0D = "N0"
Field Value
Type Description
System.String
Remarks

Since this string is intended exclusively for formatting an Integer, it overrides the default regional settings value, which is the value reported when GetLocaleInfo is called with its LCType argument set to LOCALE_IDIGITS (0x00000011, per WinNLS.h), which lives at HKEY_CURRENT_USER\Control Panel\International[iDigits] in the Windows Registry, and corresponds to the "No. of digits after decimal" property shown on the Numbers tab displayed by the Additional Settings button on the Region and Language Windows Control Panel applet dialog box.

See Also
https://msdn.microsoft.com/en-us/library/dwhawy9k(v=vs.100).aspx
INTEGER_PER_REG_SETTINGS
NUMBER_PER_REG_SETTINGS
NUMBER_PER_REG_SETTINGS_2D
NUMBER_PER_REG_SETTINGS_3D
| Improve this Doc View Source

NUMBER_PER_REG_SETTINGS_2D

Feed this string to the ToString method of any numeric value to format it according to the Regional Settings (Locale) defaults for thousands separator, decimal symbol, and number of digits to display between each thousands separator.

In contrast to NUMBER_PER_REG_SETTINGS, this string overrides the default decimal places value, and always displays two digits to the right of the decimal point.

To specify the number of places to print after the decimal point, use the static NumberPerRegSettings ( int pintFractionDigits ) method, which supports any number between zero and ninety-nine, the limits imposed by the Base Class Library.

A shortcut to get an integer formatted is IntegerPerRegSettings.

Declaration
public const string NUMBER_PER_REG_SETTINGS_2D = "N2"
Field Value
Type Description
System.String
See Also
https://msdn.microsoft.com/en-us/library/dwhawy9k(v=vs.100).aspx
NUMBER_PER_REG_SETTINGS
NUMBER_PER_REG_SETTINGS_0D
NUMBER_PER_REG_SETTINGS_3D
| Improve this Doc View Source

NUMBER_PER_REG_SETTINGS_3D

Feed this string to the ToString method of any numeric value to format it according to the Regional Settings (Locale) defaults for thousands separator, decimal symbol, and number of digits to display between each thousands separator.

In contrast to NUMBER_PER_REG_SETTINGS, this string overrides the default decimal places value, and always displays three digits to the right of the decimal point.

To specify the number of places to print after the decimal point, use the static NumberPerRegSettings ( int pintFractionDigits ) method, which supports any number between zero and ninety-nine, the limits imposed by the Base Class Library.

A shortcut to get an integer formatted is IntegerPerRegSettings.

Declaration
public const string NUMBER_PER_REG_SETTINGS_3D = "N3"
Field Value
Type Description
System.String
See Also
https://msdn.microsoft.com/en-us/library/dwhawy9k(v=vs.100).aspx
NUMBER_PER_REG_SETTINGS
NUMBER_PER_REG_SETTINGS_0D
NUMBER_PER_REG_SETTINGS_2D
| Improve this Doc View Source

PERCENT

Display a fixed point number as a percentage, using the default number of decimal places, per the Regional Settings (Locale). The number is multiplied by 100 before the formatting is applied. Hence, 0.25 renders as 25%.

To specify the number of places to print after the decimal point, use the static PercentToDecimalPlaces ( int pintFractionDigits ) method, which supports any number between zero and ninety-nine, the limits imposed by the framework.

Declaration
public const string PERCENT = "P"
Field Value
Type Description
System.String
See Also
https://msdn.microsoft.com/en-us/library/dwhawy9k(v=vs.100).aspx
PERCENT_DIGITS_2
| Improve this Doc View Source

PERCENT_DIGITS_2

Display a fixed point number as a percentage, showing two digits to the right of the decimal point.

To specify the number of places to print after the decimal point, use the static PercentToDecimalPlaces ( int pintFractionDigits ) method, which supports any number between zero and ninety-nine, the limits imposed by the framework.

Declaration
public const string PERCENT_DIGITS_2 = "P2"
Field Value
Type Description
System.String
See Also
https://msdn.microsoft.com/en-us/library/dwhawy9k(v=vs.100).aspx
PERCENT
| Improve this Doc View Source

ROUND_TRIP

Since the formatting engine ignores if for this type, there is no corresponding format string generator, and only one token, since there is no documented difference between the upper and lower case token. Before you use this token, read the documentation cited below carefully.

Declaration
public const string ROUND_TRIP = "R"
Field Value
Type Description
System.String
See Also
https://msdn.microsoft.com/en-us/library/dwhawy9k(v=vs.110).aspx#GFormatString
https://msdn.microsoft.com/en-us/library/dwhawy9k(v=vs.110).aspx
| Improve this Doc View Source

SCIENTIFIC_LC

Scientific notation, with a lower case "e" for the exponent. Exactly one digit always precedes the decimal point.

To specify the number of places to print after the decimal point, use the static PercentToDecimalPlaces ( int pintFractionDigits ) method, which supports any number between zero and ninety-nine, the limits imposed by the framework.

Declaration
public const string SCIENTIFIC_LC = "e"
Field Value
Type Description
System.String
See Also
https://msdn.microsoft.com/en-us/library/dwhawy9k(v=vs.100).aspx
| Improve this Doc View Source

SCIENTIFIC_UC

Scientific notation, with an upper case "E" for the exponent. Exactly one digit always precedes the decimal point.

Declaration
public const string SCIENTIFIC_UC = "E"
Field Value
Type Description
System.String
See Also
https://msdn.microsoft.com/en-us/library/dwhawy9k(v=vs.100).aspx

Methods

| Improve this Doc View Source

FixedPointDecimal()

Return a string suitable for formatting a fixed point number.

Declaration
public static string FixedPointDecimal()
Returns
Type Description
System.String

Format string for formatting a fixed point number with the default number of digits to the right of the decimal point.

See Also
https://msdn.microsoft.com/en-us/library/dwhawy9k(v=vs.100).aspx
FIXED
FIXED_2
FIXED_3
DECIMAL_DIGITS_DEFAULT
DECIMAL_DIGITS_MIN
DECIMAL_DIGITS_MAX
DECIMAL_DIGITS_NONE
| Improve this Doc View Source

FixedPointDecimal(Int32)

Return a string suitable for formatting a fixed point number.

Declaration
public static string FixedPointDecimal(int pintFractionDigits)
Parameters
Type Name Description
System.Int32 pintFractionDigits

Number of digits to allow to the right of the decimal point.

Returns
Type Description
System.String

Format string for formatting a fixed point number with the specified number of digits to the right of the decimal point.

See Also
https://msdn.microsoft.com/en-us/library/dwhawy9k(v=vs.100).aspx
FIXED
FIXED_2
FIXED_3
DECIMAL_DIGITS_DEFAULT
DECIMAL_DIGITS_MIN
DECIMAL_DIGITS_MAX
DECIMAL_DIGITS_NONE
| Improve this Doc View Source

FixedWidthInteger()

Return a string suitable for formatting a fixed width integer.

Declaration
public static string FixedWidthInteger()
Returns
Type Description
System.String

Format string for formatting a fixed width integer, with the default number of digits.

See Also
https://msdn.microsoft.com/en-us/library/dwhawy9k(v=vs.100).aspx
| Improve this Doc View Source

FixedWidthInteger(Int32)

Return a string suitable for formatting a fixed width integer.

Declaration
public static string FixedWidthInteger(int pintTotalDigits)
Parameters
Type Name Description
System.Int32 pintTotalDigits

Minimum number of digits to return in the formatted number.

Returns
Type Description
System.String

Format string for formatting a fixed width integer, with the specified number of digits.

See Also
https://msdn.microsoft.com/en-us/library/dwhawy9k(v=vs.100).aspx
| Improve this Doc View Source

FormatIntegerLeftPadded(Int32, Int32)

Format an integer so that it appears left padded so that its total horizontal width is a specified number of characters, which must be greater than or equal to the minimum number of characters required to render it.

Declaration
public static string FormatIntegerLeftPadded(int pintValue, int pintDesiredWidth)
Parameters
Type Name Description
System.Int32 pintValue

Specify the integer to format to occupy the greater of the number of characters required to display it or the width specified by pintDesiredWidth.

System.Int32 pintDesiredWidth

Specify the minimum desired width in characters to be occupied by the returned string, which is expected to be right-aligned and left padded with spaces.

Returns
Type Description
System.String

The return value is a string representation of pintValue formatted right-aligned in a horizontal row of at least pintDesiredWidth characters.

| Improve this Doc View Source

FormatStatusCode(Int32)

Return a string representation of a status code, formatted as hexadecimal, followed by the decimal format in parentheses.

Declaration
public static string FormatStatusCode(int pintStatusCode)
Parameters
Type Name Description
System.Int32 pintStatusCode

Though intended for use with status codes, any integer will do.

Returns
Type Description
System.String

Return a string something like 0x000000ff (255 decimal).

| Improve this Doc View Source

GeneralXPrecision(Int32)

Return a string suitable for formatting any numeric value.

Declaration
public static string GeneralXPrecision(int pintPrecisionDigits)
Parameters
Type Name Description
System.Int32 pintPrecisionDigits

Maximum number of digits to return in the formatted number.

Returns
Type Description
System.String

Format string for formatting any numeric value, with the specified number of digits.

Remarks

Since the General format differs significantly in intent and behavior, I chose to provide only one version of its format string generator, which takes an integer, which specifies the maximum number of digits to display. If more digits are required, General format reverts to scientific notation.

See Also
https://msdn.microsoft.com/en-us/library/dwhawy9k(v=vs.100).aspx
| Improve this Doc View Source

HexadecimalInteger()

Return a string suitable for formatting a hexadecimal representation of an integer with the default maximum number of numerals.

Declaration
public static string HexadecimalInteger()
Returns
Type Description
System.String

Format string for formatting an integer as a hexadecimal number.

See Also
https://msdn.microsoft.com/en-us/library/dwhawy9k(v=vs.100).aspx
HEXADECIMAL_PREFIX_0H_LC
HEXADECIMAL_PREFIX_0H_UC
HEXADECIMAL_PREFIX_0X_LC
HEXADECIMAL_PREFIX_0X_UC
| Improve this Doc View Source

HexadecimalInteger(Int32)

Return a string suitable for formatting a hexadecimal representation of an integer with the specified minimum number of numerals.

Declaration
public static string HexadecimalInteger(int pintTotalDigits)
Parameters
Type Name Description
System.Int32 pintTotalDigits

Maximum number of digits to return in the formatted number.

Returns
Type Description
System.String

Format string for formatting an integer as a hexadecimal number containing the specified minimum number of numerals.

See Also
https://msdn.microsoft.com/en-us/library/dwhawy9k(v=vs.100).aspx
HEXADECIMAL_PREFIX_0H_LC
HEXADECIMAL_PREFIX_0H_UC
HEXADECIMAL_PREFIX_0X_LC
HEXADECIMAL_PREFIX_0X_UC
| Improve this Doc View Source

IntegerPerRegSettings()

Return a string suitable for formatting an integer per the Regional Settings, overriding the default number of digits to display to the right of the decimal point to display zero digits to the right of the decimal point.

Declaration
public static string IntegerPerRegSettings()
Returns
Type Description
System.String

Format string suitable for formatting an integer

See Also
https://msdn.microsoft.com/en-us/library/dwhawy9k(v=vs.100).aspx
NUMBER_PER_REG_SETTINGS_0D
NUMBER_PER_REG_SETTINGS_2D
NUMBER_PER_REG_SETTINGS_3D
| Improve this Doc View Source

IntegerToHexStr<T>(T)

Properly formatting an integral type as a hexadecimal string, including the decorations commonly applied to them as prefix or suffix, is a bit beyond the reach of a simple ToString format string.

Declaration
public static string IntegerToHexStr<T>(T pintegralValue)
Parameters
Type Name Description
T pintegralValue

Specify the value to be formatted as hexadecimal. Integral types only, because that's the only type that may be formatted in this way.

Returns
Type Description
System.String

The returned string consists of the prefix, immediately followed by the hexadecimal number, itself, and, finally, the suffix.

Theoretically, you can have both a prefix and a suffix, but the idea is to have one or the other, but not both. You can mix and match upper and lower case glyphs in the main number string and the decorations.

Type Parameters
Name Description
T

There are no compiler enforced constraints on this type, because the Base Class Library provides no mechanism to differentiate integral types in constraints for generics. See the remarks for a comment about how we get around this.

| Improve this Doc View Source

IntegerToHexStr<T>(T, Int32)

Properly formatting an integral type as a hexadecimal string, including the decorations commonly applied to them as prefix or suffix, is a bit beyond the reach of a simple ToString format string.

Declaration
public static string IntegerToHexStr<T>(T pintegralValue, int pintTotalDigits)
Parameters
Type Name Description
T pintegralValue

Specify the value to be formatted as hexadecimal. Integral types only, because that's the only type that may be formatted in this way.

System.Int32 pintTotalDigits

Specify the minimum number of hexadecimal "digits" (glyphs, really) to render. If the number needs more than the specified number, the method uses as many as it needs, causing the returned string to be longer than you expected. If the string needs fewer characters, it is left padded with zeros.

Returns
Type Description
System.String

The returned string consists of the prefix, immediately followed by the hexadecimal number, itself, and, finally, the suffix.

Theoretically, you can have both a prefix and a suffix, but the idea is to have one or the other, but not both. You can mix and match upper and lower case glyphs in the main number string and the decorations.

Type Parameters
Name Description
T

There are no compiler enforced constraints on this type, because the Base Class Library provides no mechanism to differentiate integral types in constraints for generics. See the remarks for a comment about how we get around this.

Remarks

The available options are overloading the single-argument ToString method on all fourteen integer types, or crafting one generic method that takes the integer to format as its first argument. Since it's a lot less work, I went that route.

Although this method uses generics, there is no type constraint, because the Base Class Library offers no such constraint to filter integral types, of which there are at least fourteen, not counting BigInteger. Since the compiler won't enforce a type constraint, I wrote my own routine that enforces it at run time, by searching a table of known integral types, identified by their GUID properties. If the type of pintegralValue matches an entry in the list, the input is accepted. Otherwise, you get an ArgumentException exception that clearly explains what happened and why.

| Improve this Doc View Source

IntegerToHexStr<T>(T, Int32, NumericFormats.HexFormatDecoration)

Properly formatting an integral type as a hexadecimal string, including the decorations commonly applied to them as prefix or suffix, is a bit beyond the reach of a simple ToString format string.

Declaration
public static string IntegerToHexStr<T>(T pintegralValue, int pintTotalDigits, NumericFormats.HexFormatDecoration penmHexDecoration)
Parameters
Type Name Description
T pintegralValue

Specify the value to be formatted as hexadecimal. Integral types only, because that's the only type that may be formatted in this way.

System.Int32 pintTotalDigits

Specify the minimum number of hexadecimal "digits" (glyphs, really) to render. If the number needs more than the specified number, the method uses as many as it needs, causing the returned string to be longer than you expected. If the string needs fewer characters, it is left padded with zeros.

NumericFormats.HexFormatDecoration penmHexDecoration

The HexFormatDecoration has the Flags attribute set on it, so that it can be processed as a bit mask, enabling it to specify multiple items.

Returns
Type Description
System.String

The returned string consists of the prefix, immediately followed by the hexadecimal number, itself, and, finally, the suffix.

Theoretically, you can have both a prefix and a suffix, but the idea is to have one or the other, but not both. You can mix and match upper and lower case glyphs in the main number string and the decorations.

Type Parameters
Name Description
T

There are no compiler enforced constraints on this type, because the Base Class Library provides no mechanism to differentiate integral types in constraints for generics. See the remarks for a comment about how we get around this.

Remarks

The available options are overloading the single-argument ToString method on all fourteen integer types, or crafting one generic method that takes the integer to format as its first argument. Since it's a lot less work, I went that route.

Although this method uses generics, there is no type constraint, because the Base Class Library offers no such constraint to filter integral types, of which there are at least fourteen, not counting BigInteger. Since the compiler won't enforce a type constraint, I wrote my own routine that enforces it at run time, by searching a table of known integral types, identified by their GUID properties. If the type of pintegralValue matches an entry in the list, the input is accepted. Otherwise, you get an ArgumentException exception that clearly explains what happened and why.

| Improve this Doc View Source

IntegerToHexStr<T>(T, NumericFormats.HexFormatDecoration)

Properly formatting an integral type as a hexadecimal string, including the decorations commonly applied to them as prefix or suffix, is a bit beyond the reach of a simple ToString format string.

Declaration
public static string IntegerToHexStr<T>(T pintegralValue, NumericFormats.HexFormatDecoration penmHexDecoration)
Parameters
Type Name Description
T pintegralValue

Specify the value to be formatted as hexadecimal. Integral types only, because that's the only type that may be formatted in this way.

NumericFormats.HexFormatDecoration penmHexDecoration

The HexFormatDecoration has the Flags attribute set on it, so that it can be processed as a bit mask, enabling it to specify multiple items.

Returns
Type Description
System.String

The returned string consists of the prefix, immediately followed by the hexadecimal number, itself, and, finally, the suffix.

Theoretically, you can have both a prefix and a suffix, but the idea is to have one or the other, but not both. You can mix and match upper and lower case glyphs in the main number string and the decorations.

Type Parameters
Name Description
T

There are no compiler enforced constraints on this type, because the Base Class Library provides no mechanism to differentiate integral types in constraints for generics. See the remarks for a comment about how we get around this.

| Improve this Doc View Source

NumberPerRegSettings()

Return a string suitable for formatting an integer or fixed point number, per the Regional Settings, overriding the default number of digits to display to the right of the decimal point, if necessary, to display two digits to the right of the decimal point.

Declaration
public static string NumberPerRegSettings()
Returns
Type Description
System.String

Format string suitable for formatting an integer or fixed point number

See Also
https://msdn.microsoft.com/en-us/library/dwhawy9k(v=vs.100).aspx
NumberPerRegSettings()
NumberPerRegSettings(Int32)
NUMBER_PER_REG_SETTINGS_0D
NUMBER_PER_REG_SETTINGS_2D
NUMBER_PER_REG_SETTINGS_3D
| Improve this Doc View Source

NumberPerRegSettings(Int32)

Return a string suitable for formatting an integer or fixed point number, per the Regional Settings, overriding the default number of digits to display to the right of the decimal point, if necessary, to display a specified number of digits to the right of the decimal point.

Declaration
public static string NumberPerRegSettings(int pintFractionDigits)
Parameters
Type Name Description
System.Int32 pintFractionDigits

Maximum number of digits to return in the formatted number.

Returns
Type Description
System.String

Format string suitable for formatting an integer or fixed point number with a specified number of digits to the right of the decimal point.

See Also
https://msdn.microsoft.com/en-us/library/dwhawy9k(v=vs.100).aspx
NUMBER_PER_REG_SETTINGS_0D
NUMBER_PER_REG_SETTINGS_2D
NUMBER_PER_REG_SETTINGS_3D
| Improve this Doc View Source

PercentToDecimalPlaces()

Return a string suitable for formatting an integer or fixed point number as a percentage, with two places to the right of the decimal point.

Declaration
public static string PercentToDecimalPlaces()
Returns
Type Description
System.String

Format string suitable for formatting an integer or fixed point number as a percentage.

See Also
https://msdn.microsoft.com/en-us/library/dwhawy9k(v=vs.100).aspx
PERCENT
PERCENT_DIGITS_2
| Improve this Doc View Source

PercentToDecimalPlaces(Int32)

Return a string suitable for formatting an integer or fixed point number as a percentage, with two places to the right of the decimal point.

Declaration
public static string PercentToDecimalPlaces(int pintFractionDigits)
Parameters
Type Name Description
System.Int32 pintFractionDigits

Maximum number of digits to return in the formatted number.

Returns
Type Description
System.String

Format string suitable for formatting an integer or fixed point number as a percentage, displaying a specified number of digits to the right of the decimal point.

See Also
https://msdn.microsoft.com/en-us/library/dwhawy9k(v=vs.100).aspx
PERCENT
PERCENT_DIGITS_2
| Improve this Doc View Source

ScientificXPrecisionLC(Int32)

Return a string suitable for formatting any numeric value in scientific notation.

Declaration
public static string ScientificXPrecisionLC(int pintFractionDigits)
Parameters
Type Name Description
System.Int32 pintFractionDigits

Maximum number of digits to return in the formatted number.

Returns
Type Description
System.String

Format string for formatting any numeric value, with the specified number of digits, in scientific notation.

The exponent is lower case.

Remarks

Since the Scientific format differs significantly in intent and behavior, I chose to provide only one version of its format string generator, which takes an integer, which specifies the maximum number of digits to display.

See Also
https://msdn.microsoft.com/en-us/library/dwhawy9k(v=vs.100).aspx
ScientificXPrecisionUC(Int32)
SCIENTIFIC_LC
SCIENTIFIC_UC
| Improve this Doc View Source

ScientificXPrecisionUC(Int32)

Return a string suitable for formatting any numeric value in scientific notation.

Declaration
public static string ScientificXPrecisionUC(int pintFractionDigits)
Parameters
Type Name Description
System.Int32 pintFractionDigits

Maximum number of digits to return in the formatted number.

Returns
Type Description
System.String

Format string for formatting any numeric value, with the specified number of digits, in scientific notation.

The exponent is lower case.

Remarks

Since the Scientific format differs significantly in intent and behavior, I chose to provide only one version of its format string generator, which takes an integer, which specifies the maximum number of digits to display.

See Also
https://msdn.microsoft.com/en-us/library/dwhawy9k(v=vs.100).aspx
ScientificXPrecisionLC(Int32)
SCIENTIFIC_LC
SCIENTIFIC_UC
  • Improve this Doc
  • View Source
Back to top Generated by DocFX