/ Published in: JavaScript
Use this to convert JavaScript numbers to official scientific standard form (e.g. 1.54 × 10^3)
Uses HTML <sup> tags and × symbol
Example:
var number = 4.223e20;
var stnd = standardForm(number);
// stnd = 4.223 x 10^20
Uses HTML <sup> tags and × symbol
Example:
var number = 4.223e20;
var stnd = standardForm(number);
// stnd = 4.223 x 10^20
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
function standardForm(s) { var indexOfE = s.indexOf('e'); if(indexOfE != -1) { var s_start = s.substr(0,indexOfE) + ' × 10'; var s_index = (s.charAt(indexOfE+1) == '+') ? s.substring(indexOfE+2,s.length) : s.substring(indexOfE+1,s.length); var s_end = '<sup>'+s_index+'</sup>'; return s_start+s_end; } else { return s; } }
URL: http://astrophysicsonline.info/resources/calculator.php