Venciity

[Jumpstart C#] Console Demos - Regional Settings

Jan 22nd, 2014
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.40 KB | None | 0 0
  1. using System;
  2. using System.Text;
  3. using System.Threading;
  4. using System.Globalization;
  5.  
  6. namespace RegionalSettings
  7. {
  8.     class RegionalSettingsDemo
  9.     {
  10.         static void Main()
  11.         {
  12.             Console.OutputEncoding = Encoding.Unicode;
  13.             //CultureInfo invariantCulture = CultureInfo.InvariantCulture;
  14.             //CultureInfo usCulture = new CultureInfo("en-US");
  15.             //CultureInfo bgCulture = new CultureInfo("bg-BG");
  16.             //CultureInfo configCulture = new CultureInfo(Properties.Settings.Default.DefaultCulture); //get a setting from the app.config file
  17.  
  18.  
  19.             //Thread.CurrentThread.CurrentCulture = usCulture;
  20.  
  21.             double value = 3.54;
  22.             Console.WriteLine("The value is: {0}", value);
  23.  
  24.             // Two possible outputs:
  25.             //  - The value is 3.54
  26.             //  - The value is 3,54
  27.  
  28.             decimal money = 100.5M;
  29.             Console.WriteLine("I have {0:C} in my wallet.", money);
  30.  
  31.  
  32.             Console.Write("Please enter a value: ");
  33.             // Try entering "1.56" and also "1,2,3,4,5"
  34.             decimal d = Decimal.Parse(Console.ReadLine());
  35.             Console.WriteLine(d);
  36.  
  37.             // Change the decimal separator to "."
  38.  
  39.             Console.WriteLine("The value in InvariantCulture is: {0}", d.ToString(CultureInfo.InvariantCulture));
  40.             // The value is 3.54
  41.  
  42.         }
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment