How to use power notation in HTML?

Asked

Viewed 10,050 times

7

How to format 2 numbers in power?

Example:

2, 2 = 2²
3, 2 = 3²
5, 3 = 5³
6, 2 = 6²
  • You speak of calculate a power or format a number as power?

  • format a number as power!!!

  • 2

    Formatting numbers is not a javascript problem. it is an HTML problem

  • how to format by html in potential ? remembering that I have this number for example "2,2" and need to turn "2²"

  • This DIT of yours with the second question changes the question. I’ll go back, if you don’t agree say, or ask another question...

  • I asked you a new question......

Show 1 more comment

2 answers

9

The HTML element <sup> can be used to put a text in this form:

2<sup>3</sup>

Vira: 23.

Alternatively, you can use the unicode characters for superscript (although only a few of them are supported):

2&#x00B3;

2³ In this case it would be necessary to map each number of 0 to 9 to his code point correspondent.

5

If you have this value in a string as you put it can do so:

var x = '2,5';
var partes = x.split(',');
var htmlString = partes[0] + '<sup>' + partes[1] + '</sup>';

Example: http://jsfiddle.net/rbcg7hxL/

Browser other questions tagged

You are not signed in. Login or sign up in order to post.