0

I am writing a simple android app and I would like to set the text of a button to be X^n but I want it to look the same way as it would if you would write it on a piece of paper( for example 2⁶).

I know there are several unicode characters that does it for a small group of numbers but I am looking for a generel function (or any other way) that takes two integers and output the first by the power of the second. For example:

int X=2;
int n=6;
function(X , n) ==> 2⁶

I know a similar question was asked here before but its answers were not sufficient because I want to use variables' values and not actual numbers;

Thanks!

1 Answers1

1

You can use html's <sup> tags for that:

button.setText(Html.fromHtml("X<sup>n</sup>"));
Simas
  • 43,548
  • 10
  • 88
  • 116