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);
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:
If you are using the default console font of Lucinda Console, then the results are the same.
Here's superscripts and subscripts
wikipedia
And here's how to escape unicode characters in c#
MSN
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With