Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible write 10^2 in a special way?

Is it possible to write 10² or 10³ in C#?

For example in a label or Console output.

I also want use it for other powers (104, 105, ...).

Something like:

string specialNumber = string.Format("10^4");
System.Console.Write(specialNumber);
like image 873
user2261524 Avatar asked Jun 27 '13 13:06

user2261524


2 Answers

This is really two different questions. One for the console, and one for a GUI app. I'm choosing to cover the console.

If you just need powers 2 and 3 you can do this:

Console.WriteLine("10²");
Console.WriteLine("10³");

This makes use of characters U+00B2 and U+00B3.

If it turns out that you require different powers then you are out of luck at the console. Whilst there are Unicode characters for other numerals, font support is poor and you will have no success with code like this:

Console.WriteLine("10⁴");
Console.WriteLine("10⁵");
Console.WriteLine("10⁶");
// etc.

Many commonly used console fonts do not include superscript glyphs for these characters. For example, this is what it looks like on my machine using Consolas:

enter image description here

If you are using the default console font of Lucinda Console, then the results are the same.

like image 160
David Heffernan Avatar answered Nov 15 '22 07:11

David Heffernan


Here's superscripts and subscripts

wikipedia

And here's how to escape unicode characters in c#

MSN

like image 30
Jonesopolis Avatar answered Nov 15 '22 05:11

Jonesopolis