C# Int64 ToString(String, IFormatProvider)

Description

Int64 ToString(String, IFormatProvider) converts the numeric value of this instance to its equivalent string representation using the specified format and culture-specific format information.

Syntax

Int64.ToString(String, IFormatProvider) has the following syntax.


public string ToString(
  string format,
  IFormatProvider provider
)

Parameters

Int64.ToString(String, IFormatProvider) has the following parameters.

  • format - A numeric format string.
  • provider - An object that supplies culture-specific formatting information about this instance.

Returns

Int64.ToString(String, IFormatProvider) method returns The string representation of the value of this instance as specified by format and provider.

Example

The following example displays a positive and a negative value using each of the supported standard numeric format specifiers for three different cultures.


using System.Globalization;
using System;/* ww  w.j  a va 2 s. co  m*/
public class MainClass{
  public static void Main(String[] argv){  
    // Define cultures whose formatting conventions are to be used.
    CultureInfo[] cultures = {CultureInfo.CreateSpecificCulture("en-US"), 
                              CultureInfo.CreateSpecificCulture("fr-FR"), 
                              CultureInfo.CreateSpecificCulture("es-ES") };
    long positiveNumber = 1234;
    long negativeNumber = -1234;
    string[] specifiers = {"G", "C", "D8", "E2", "F", "N", "P", "X8"}; 
    
    foreach (string specifier in specifiers)
    {
       foreach (CultureInfo culture in cultures)
       {
          // Display values with "G" format specifier.
          Console.WriteLine("{0} format using {1} culture: {2, 16} {3, 16}",  
                            specifier, culture.Name, 
                            positiveNumber.ToString(specifier, culture), 
                            negativeNumber.ToString(specifier, culture));
       }
       Console.WriteLine();
    }

  }
}
    

The code above generates the following result.





















Home »
  C# Tutorial »
    System »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version