Implement Format for different Culture Information : Culture Format : I18N Internationalization C# Examples


C# Examples » I18N Internationalization » Culture Format »

 

Implement Format for different Culture Information









    
using  System;
using  System.Globalization;

public  sealed  class  ComplexNumber  :  IFormattable
{
        public  ComplexNumber(  double  real,  double  imaginary  )  {
                this.real  =  real;
                this.imaginary  =  imaginary;
        }

        public  override  string  ToString()  {
                return  ToString(  "G",  null  );
        }

        public  string  ToString(  string  format,  IFormatProvider  formatProvider  )  {
                string  result  =  "("  +  real.ToString(format,  formatProvider)  +  "  "  +  real.ToString(format,  formatProvider)  +  ")";
                return  result;
        }
      
        private  readonly  double  real;
        private  readonly  double  imaginary;
}

public  sealed  class  MainClass
{
        static  void  Main()  {
                ComplexNumber  num1  =  new  ComplexNumber(  1.12345678,  2.12345678  );
                
                Console.WriteLine(  "US  format:  {0}",  num1.ToString(  "F5",  new  CultureInfo("en-US")  )  );
                Console.WriteLine(  "DE  format:  {0}",  num1.ToString(  "F5",  new  CultureInfo("de-DE")  )  );
                Console.WriteLine(  "Object.ToString():  {0}",num1.ToString()  );
        }
}
    
   
  
   




HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo I18N Internationalization
» Culture Format