Send feedback on this topic.
Teradata.Client.Provider
ToString(String,IFormatProvider) Method
Example 



Teradata.Client.Provider Namespace > TdNumber Structure > ToString Method : ToString(String,IFormatProvider) Method
The format information
An IFormatProvider that supplies culture-specific formatting information.
Converts this instance to its equivalent String representation using the specified format and culture-specific format information.
Syntax
'Declaration
 
Public Overloads Function ToString( _
   ByVal format As String, _
   ByVal formatProvider As IFormatProvider _
) As String
'Usage
 
Dim instance As TdNumber
Dim format As String
Dim formatProvider As IFormatProvider
Dim value As String
 
value = instance.ToString(format, formatProvider)
public string ToString( 
   string format,
   IFormatProvider formatProvider
)
public:
String^ ToString( 
   String^ format,
   IFormatProvider^ formatProvider
) 

Parameters

format
The format information
formatProvider
An IFormatProvider that supplies culture-specific formatting information.

Return Value

The String representation of this instance as specified by format and provider.
Exceptions
ExceptionDescription
An incorrect format specifier is contained in the format string.
Remarks

The format string is specified as

<Format Specifier><Precision Specifier>

A null can be passed in as the format string. When this is done, the 'G' is used as the Format Specifier.

The maximum number of digits that will appear in the string conversion of a TdNumber is 40.

The following Format Specifiers are supported:

Format Specifier Description
c or C

Currency. Before the number gets converted into a string that represents currency, it is expanded (the exponent is applied to the mantissa). The precision specifier is applied to the digits that are to the right of the decimal point. For example, when the number 6.8737251092e5 is converted and "C4" is specified as the format, the result is "$687372.5109".

e or E

Exponential notation. The precision specifier is used to indicate how many digits are to appear to the right of the decimal point. For example, when the number 9.3413442e-50 is converted to a string and "E3" is specified as the format, the result is "9.341e-050".

f or F

Fixed numeric Format. Before the number gets converted into a string, it is expanded (the exponent is applied to the mantissa). After the number is expanded, the precision specifier is applied to the digits that are to the right of the decimal point. For example, when the number 3.45495874721e4 is converted to a string and "F2" is specified as the format, the result is "34549.59".

g or G

General numeric format.

n or N

Number format. The exponent is applied to the mantissa. After the number has been expanded the group and decimal separators are added to the numeric string.

The Precision Specifier indicates how many decimal places will appear in the string. It does not have to be specified. A valid Precision Specifier is between 0 - 99.

For more information on each of the supported Format Specifiers please refer to Standard Numeric Format Strings in MSDN.

When a number is converted to a string, its format is controlled by the Globalization.NumberFormatInfo. For each specifier, this object contains formatting information that will be used when constructing the numeric string.

Custom format strings are not currently supported by TdNumber.

Example

The following is an example on formatting a TdNumber when converting to a String.

public void ToStringExample()
{
    TdNumber value;
    String result;
             
    System.Globalization.NumberFormatInfo formatInfo;
             
    value = TdNumber.Parse("9987365422318132e-8");
             
    // FIXED FORMAT
    
    // Using Default FormatProvider.
             
    // result will be 99873654.22
    result = value.ToString("f2");
             
    // result will be 99873654.2232
    result= value.ToString("f4");
             
    // Going to change the the Decimal Separator
    formatInfo.NumberDecimalSeparator = "##";
   
    // result will be 99873654##223218
    result = value.ToString("f6");
             
    // CURRENCY FORMAT
             
    // result will be $99,873,654.22
    result = value.ToString("C2");
             
    // Going to change the Currency Group Separator
    numberFormat.CurrencyGroupSeparator = @"@@";
    
    // Going to chage the Currency Symbol
    numberFormat.CurrencySymbol = "?";
             
    // result will be ?99@@873@@654.22
    //     NOTE:  There is a property, CurrencyDecimalSeparator,
    //            that is used only for currency.  Therefore,
    //            NumberDecimalSeparator has no affect 
    //            on a string formatted with a "c".
    result = value.ToString("c4");
}
Requirements

Target Platforms: Windows 8.1, Windows 10, Windows Server 2012 R2, Windows Server 2016, Windows Server 2019

See Also

Reference

TdNumber Structure
TdNumber Members
Overload List