CSharp - Write program to Read Localized Numeric Input

Requirements

You will read numeric input in a specific localization, regardless of the Windows settings.

Write a program that reads a decimal number with two fixed-language settings, American and Czech.

Hint

To work with specific localizations, use the CultureInfo object.

Import System.Globalization namespace

Demo

using System;
using System.Globalization;
class Program// ww w. j  a  va  2 s  .  c o  m
{
    static void Main(string[] args)
    {
        // AMERICAN 
        CultureInfo american = new CultureInfo("en-US");
        try
        {
            // Input 
            Console.Write("Enter American decimal number: ");
            string input = Console.ReadLine();
            double number = Convert.ToDouble(input, american);

            // Output 
            Console.WriteLine("You have entered " + number);
        }
        catch (Exception)
        {
            Console.WriteLine("Incorrect input");
        }

        // CZECH 
        CultureInfo czech = new CultureInfo("cs-CZ");
        try
        {
            Console.Write("Enter Czech decimal number: ");
            string input = Console.ReadLine();
            double number = Convert.ToDouble(input, czech);

            // Output 
            Console.WriteLine("You have entered " + number);
        }
        catch (Exception)
        {
            Console.WriteLine("Incorrect input");
        }
    }
}

Result