How does one set text of two labels with two different cultural/region format options?

896 views Asked by At

How does one set text of two labels with two different cultural/region format options? For first label to be ar-EG : Arabic - Egypt and second one to be en-US : English - United States ?

This to be done for Number/Date/Time/Currency formats.

2

There are 2 answers

2
josecortesp On

I think this maybe can solve your problem:

I needed to show different money values in two differents cultural format. So i did this right after each of the code-line asingning the value:

CultureInfo US = new CultureInfo("en-US");
Thread.CurrentThread.CurrentCulture = US;

// Asign your label here

CultureInfo AR = new CultureInfo("ar-EG");  
Thread.CurrentThread.CurrentCulture = AR;

//Asign label here

Just remember to add the folowing namespace to the top of your code-file:

using System.Threading;
using System.Globalization;

and to re-set the previous culture. You can even override the System culture info just by adding those lines on the program.cs

0
Hans Passant On

Use the culture explicitly in the ToString() method. For example:

  DateTime dt = DateTime.Now;
  CultureInfo arabic = CultureInfo.GetCultureInfo("ar-EG");
  label1.Text = dt.ToString(arabic.DateTimeFormat);
  CultureInfo english = CultureInfo.GetCultureInfo("en-US");
  label2.Text = dt.ToString(english.DateTimeFormat);

Use CultureInfo.NumberFormat to format numbers.