0
        Console.Write("Please type in the first floating point number: ");
        double floating_1 = Convert.ToDouble(Console.ReadLine());
        Console.Write("Please type in the second floating point number: ");
        double floating_2 = Convert.ToDouble(Console.ReadLine());

        double product = floating_1 * floating_2;
        double difference = floating_1 - floating_2;
        double sum = floating_1 + floating_2;

        Console.WriteLine("The product of the two floating point numbers is: " + product + "\nThe sum of the two floating point numbers is: " + sum + "\nThe difference between the two floating point numbers is: " + difference);
        Console.ReadLine();

我有这段代码。每当我执行程序时,小数点显示不正确(如数字:45.23 将显示为 4523)。

4

1 回答 1

1

我的猜测是您的国家/地区设置设置为使用 ,而不是 . 确定小数。

尝试输入例如 14,5 而不是 14.5 看看会发生什么。

c# 根据您的国家/地区默认值解析数字输入并格式化数字输出

于 2012-09-26T08:29:03.037 回答