0

Simply speaking console displays positive infinity as ? instead of . Example code:

var a = double.PositiveInfinity;
Console.WriteLine(a); //displays ? instead of ∞

I have tried using Invariant Culture, Console.OutputEncoding = System.Text.Encoding.UTF8, and Console.OutputEncoding = System.Text.Encoding.Unicode. Always displays ?.

P.S

Writing it to a file does work and it displays correctly, but it would be nice if it also displayed properly on console.

  • What platform?? – Daniel A. White Jan 11 '23 at 17:36
  • @DanielA.White Windows 10, .net 6.0. –  Jan 11 '23 at 17:40
  • Does it show like you'd expect if you use Windows Terminal if you're currently using the old `cmd` console host instead? – Martin Costello Jan 11 '23 at 17:41
  • @MartinCostello doesn't work when launched through Visual Studio 2022, doesn't work in Windows Terminal either. The same about cmd. –  Jan 11 '23 at 17:47
  • Setting `Console.OutputEncoding = System.Text.Encoding.Unicode` worked on my machine. I think it might depend on the codepage used by console and maybe font. – Mike Mozhaev Jan 11 '23 at 17:58
  • @MikeMozhaev I guess I will look into it further, but it means I'm on the right track. –  Jan 11 '23 at 18:01
  • Unicode Encoding is not enough. The Console **Font** needs to support the specific glyph, too. => https://www.fileformat.info/info/unicode/block/mathematical_operators/fontsupport.htm In my Windows 10 the default font is Consolas. Assuming yours is, too: it only supports 7% of that block. – Fildor Jan 11 '23 at 18:10
  • Funny enough, it lists "infinity" (U+221E) as supported ... strange. AND prints it. What's your font? – Fildor Jan 11 '23 at 18:15
  • When i try on my linux machine, all work fine. It display ∞. Maybe the encoded char in your cmd. Try [this](https://stackoverflow.com/a/388500/9455573) – piferrari Jan 11 '23 at 18:58
  • Does running `chcp 65001` beforehand work? – Michael Stum Jan 11 '23 at 22:18

0 Answers0