C# - CultureInfo.InvariantCulture的概率问题

时间:2013-11-21 14:45:04

标签: c# decimal output

我在下面的代码中输出有问题。

using System;
using System.Globalization;

class GreaterNum
{
    static void Main()
    {
        double num1 = 0;
        double num2 = 0;

        System.Threading.Thread.CurrentThread.CurrentCulture = 
        System.Globalization.CultureInfo.InvariantCulture;

        Console.Write("Enter first number: ");
        bool isDouble1 = Double.TryParse(Console.ReadLine(), out num1);

        Console.Write("Enter second number: ");
        bool isDouble2 = Double.TryParse(Console.ReadLine(), out num2);

        if (isDouble1 && isDouble2)
        {
                Console.WriteLine("The greater number is: " + Math.Max(num1, num2));
        }
        else
        {
                Console.WriteLine("Not a valid number!");
        }
    }
}

问题是当数字不是小数时“。”输出是:

输入第一个数字:1,2 输入第二个数字:2,3 数字越大:23

1 个答案:

答案 0 :(得分:2)

尝试同时设置System.Threading.Thread.CurrentThread.CurrentUICulture

System.Threading.Thread.CurrentThread.CurrentUICulture = 
        System.Globalization.CultureInfo.InvariantCulture;