Instead of a currency symbol, I get a question mark on the command line

I am using 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 double.

How can I fix this problem?

My conclusion: qmarkc #

 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 have added my code. Just a simple but valid job :(

Update: Updated code to use Console.OutputEncoding = System.Text.Encoding.Unicode; as well as my currency and console settings are shown below: enter image description here

The problem you can see is that although I updated my code to use unicode, changed my CMD settings to use the Lucida Console font, when I run the program from VS, the font remains the same version of bitmap fonts.

LAST EDIT: Here's how to quickly and easily change the console font used by the Visual Studio console. Now the currency is correctly displayed in my program: The font of the management console and the layout used by the C # .NET console application

+6
source share
3 answers

This is by design.

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

In this font, there is no need to have a symbol for your currency so that the symbol may not display correctly. See this link for supported currency symbols in the Lucida console.

You cannot easily fix this in a console application just because changing the font used to display text on the console is not so simple (perhaps with some WinAPI calls, I suppose).

+2
source

Add

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

before writing output.

You should also make sure the font is TrueType console.

+6
source

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

It was not enough for me , the question mark was replaced by even more unreadable characters. The font used by my console program did not support the euro sign.

The Lucios console and the Console both do.

To verify that the correct font is started by default:

  • Launch the console program (using visual studio).
  • Select a control unit in the upper left corner
  • Select "Default" from the drop-down menu.
  • On the fonts tabs, select Lucida Console and the size that is more convenient for you

Now, the next time you start your console program in a visual studio, the euro sign is displayed correctly.

0
source

Source: https://habr.com/ru/post/983868/


All Articles