我在命令提示符中出现了一个问号,而不是货币符号 [英] Instead of currency symbol I get a question mark into the Command Prompt

查看:79
本文介绍了我在命令提示符中出现了一个问号,而不是货币符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Windows 7,Visual Studio 2013,C#和.NET 4.5.

我的问题是下面一行的输出:

 Console.WriteLine("Car`s value: {0:C} ", myNewCar.determineMarketValue());

myNewCar.determineMarketValue()返回一个双精度值.

如何解决此问题?

我的输出是这样的:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Lesson15SimpleClasses
{
    class Program
    {

        static void Main(string[] args)
        {
            Car myNewCar = new Car();
            myNewCar.Make = "Oldsmobile";
            myNewCar.Model = "Cutlas Supreme";
            myNewCar.Year = 1986;
            myNewCar.Color = "Silver";

            Console.OutputEncoding = System.Text.Encoding.Unicode; 

                Console.WriteLine("{0} - {1} - {2}",
                myNewCar.Make,
                myNewCar.Model,
                myNewCar.Color);


            Console.WriteLine("Car`s value: {0:C} ", myNewCar.determineMarketValue());

            Console.ReadLine();
        }

    }

    class Car
    {

        public string Make { get; set; }
        public string Model { get; set; }
        public int Year { get; set; }
        public string Color { get; set; }

        public double determineMarketValue()
        {
            double carValue = 100.0;

            if (this.Year > 1990)
                carValue = 10000.0;
            else
                carValue = 2000.0;

            return (carValue);
        }

    }


}

我添加了我的代码..so如此简单,但却能完成工作:(

更新:代码已更新为使用Console.OutputEncoding = System.Text.Encoding.Unicode; 以及我的货币和控制台设置如下所示:

您所看到的问题是,即使我更新了代码以使用unicode,但从VS执行程序时,我的cmd设置仍更改为使用Lucida Console字体,字体仍保持相同的栅格字体选项.

最后这里是如何快速,简单地更改Visual Studio控制台使用的控制台字体.现在货币正确显示在我的程序中:解决方案

这是设计使然.

.NET控制台应用程序使用某种预定义的系统字体(通常是Lucida Console,但可以是Consolas或其他类似字体)输出文本.

该字体不必要带有您的货币符号,因此该符号可能无法正确显示.有关Lucida支持的货币符号,请参见此链接.控制台.

您不能轻易地在控制台应用程序中修复它,因为更改在控制台中显示文本所用的字体不是那么容易(我想有些WinAPI调用是可能的).

I use Windows 7, Visual Studio 2013, C# and .NET 4.5.

My problem is the output of the line below :

 Console.WriteLine("Car`s value: {0:C} ", myNewCar.determineMarketValue());

myNewCar.determineMarketValue() returns a double.

How can I fix this problem?

My output is this:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Lesson15SimpleClasses
{
    class Program
    {

        static void Main(string[] args)
        {
            Car myNewCar = new Car();
            myNewCar.Make = "Oldsmobile";
            myNewCar.Model = "Cutlas Supreme";
            myNewCar.Year = 1986;
            myNewCar.Color = "Silver";

            Console.OutputEncoding = System.Text.Encoding.Unicode; 

                Console.WriteLine("{0} - {1} - {2}",
                myNewCar.Make,
                myNewCar.Model,
                myNewCar.Color);


            Console.WriteLine("Car`s value: {0:C} ", myNewCar.determineMarketValue());

            Console.ReadLine();
        }

    }

    class Car
    {

        public string Make { get; set; }
        public string Model { get; set; }
        public int Year { get; set; }
        public string Color { get; set; }

        public double determineMarketValue()
        {
            double carValue = 100.0;

            if (this.Year > 1990)
                carValue = 10000.0;
            else
                carValue = 2000.0;

            return (carValue);
        }

    }


}

I added my code ..so simple yet doent work :(

Update: Code updated to use Console.OutputEncoding = System.Text.Encoding.Unicode; and also my currency and console setting are shown below:

The problem as you can see is that even though i updated my code to use unicode changed my cmd settings to use Lucida Console font when i execute the program from VS the font remains the same Raster fonts option.

LAST EDIT:Here is how to change the console font used by Visual Studio console fast and simple.Now currency appears correctly in my program : Control console font & layout used by C# .NET console application

解决方案

It is by design.

.NET console application outputs text using some predefined system font (usually Lucida Console, but it can be Consolas or other similar font).

That font not necessary has symbol for your currency, so that symbol can be displayed incorrectly. See this link for supported currencies symbols in Lucida Console.

You can't easily fix it in console application just because it is not so easy to change font used for displaying text in console (it is possible with some WinAPI calls, I suppose).

这篇关于我在命令提示符中出现了一个问号,而不是货币符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆