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



Teradata.Client.Provider Namespace > TdDecimal 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 TdDecimal
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.
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 following Format Specifiers are supported:

Format Specifier Description
c or C

Currency.

e or E

Exponential notation.

f or F

Fixed numeric Format.

g or G

General numeric format.

n or N

Number format.

p or P

Percent format.

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 TdDecimal.

Example

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

public void ToStringExample()
{
    TdDecimal value;
    String result;
             
    System.Globalization.NumberFormatInfo formatInfo;
             
    value = TdDecimal.Parse("99873654.22318132");
             
    // 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

TdDecimal Structure
TdDecimal Members
Overload List