-1

I am trying to learn about NumberFormatInfo.NegativeSign Property, and put in the following code in VS.

CultureInfo ci = CultureInfo.CreateSpecificCulture ("");
ci.NumberFormat.NegativeSign = "\u203E";
double[] numbers = { -1.0, -16.3, -106.35 };

foreach (var number in numbers)
   Console.WriteLine (number.ToString (culture));

Since I got a number of errors, I modified it to...

System.Globalization.CultureInfo ci = System.Globalization.CultureInfo.CreateSpecificCulture ("");
ci.NumberFormat.NegativeSign = "\u203E";
double[] numbers = { -1.0, -16.3, -106.35 };

foreach (var number in numbers)
    Console.WriteLine (number.ToString (ci));

And it compiled fine. But the output was:

?1
?16.3
?106.35

I got the code from .Net library framework definitions on Microsoft page here and the Unicode was supposed to change the negative sign to the OVERLINE character. Did I do anything wrong? Why am I getting the "?" sign instead?

I did not know about the console output configuration requirement. Thanks. One other item; the original code used culture instead of ci in the last line. I assumed that was a typo and changed it. I hope I was not wrong. The following are the lines they have:

CultureInfo ci = CultureInfo.CreateSpecificCulture ("");
ci.NumberFormat.NegativeSign = "\u203E";
double[] numbers = { -1.0, -16.3, -106.35 };

foreach (var number in numbers)
    Console.WriteLine (number.ToString (culture));

I tried to post a question today, I got a message that I may lose access to the this site. I have no idea who or how evaluates the content of a question. I am also not sure why I receive this prompt when there was not negative feedback on any of my questions. None of the questions asked were redundant, and they met the guidelines provided on the site.

maverick
  • 191
  • 8
  • are you at least sure the console charset can render it ? – Sehnsucht Oct 08 '16 at 23:28
  • Are you sure the font you're using to display supports that character? Did you remember to set the console encoding to Unicode? Those are the two most likely explanations, but without a good [mcve] that reliably reproduces the problem, it's impossible to know for sure what your issue is. – Peter Duniho Oct 08 '16 at 23:29

1 Answers1

1

The console can by default not display unicode characters. You need to specifically enable that using the following line before your own code:

Console.OutputEncoding = System.Text.Encoding.Unicode;
NineBerry
  • 26,306
  • 3
  • 62
  • 93