How to use power notation in HTML?

6

How to format 2 numbers in power?

Example:

2, 2 = 2²
3, 2 = 3²
5, 3 = 5³
6, 2 = 6²
    
asked by anonymous 03.09.2014 / 21:51

2 answers

8

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

2<sup>3</sup>

Turns: 2 3 .

Alternatively, you can use Unicode characters for superscript (although only a few are supported):

2&#x00B3;

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

    
03.09.2014 / 21:56
5

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

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

Example: link

    
03.09.2014 / 22:00