Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div class="container">
<h1>toExponential()</h1>
<h2>Overview</h2>

<p>This method is part of the Number Object prototype and can be called on any object that is a Number, it converts a number to be displayed as an exponent. An exponent is displayed with e+# with # representing the number of places to move a decimal point. Read more about exponential numbers here: <a href="https://en.wikipedia.org/wiki/Scientific_notation">https://en.wikipedia.org/wiki/Scientific_notation</a>.</p>

<h2>Syntax</h2>
<code>number.toExponential( [fractionDigits] );</code>

<h2>Parameters</h2>

<p>The <code>toExponential()</code> method takes one optional parameter called 'fractionDigits'. 'fractionDigits' is a whole number, specifying the number of digits after the decimal point to display before displaying the exponential.</p>

<p>If 'fractionDigits' is not specified, then the number of digits will be the number need to represent the value uniquely.</p>

<h2>Examples</h2>

<p>These examples are taken from the Mozilla Developer Network.</p>

<pre class="ng-scope">var numObj = 77.1234;

console.log(numObj.toExponential());  // logs 7.71234e+1
console.log(numObj.toExponential(4)); // logs 7.7123e+1
console.log(numObj.toExponential(2)); // logs 7.71e+1
console.log(77.1234.toExponential()); // logs 7.71234e+1
console.log(77.toExponential());      // logs 7.7e+1</pre>

<h2>Using a number object</h2>
<p>The result of <code>var num = new Number(9234.4354);</code> is <code class="output1"></code></p>

<p>The result of <code>num.toExponential();</code> is <code class="output2"></code></p>

<p>The result of <code>num.toExponential(1);</code> is <code class="output3"></code></p>

<p>The result of <code>num.toExponential(2);</code> is <code class="output4"></code></p>

<p>The result of <code>num.toExponential(10);</code> is <code class="output5"></code></p>

<p>The result of <code>num.toExponential(-2);</code> is <code class="output6">Uncaught RangeError: toExponential() argument must be between 0 and 20</code></p>

<p>The result of <code>num.toExponential(0);</code> is <code class="output7"></code></p>

<h2>Using just a variable set as a number</h2>
<p>The result of <code>var number = 852.46;</code> is <code class="output8"></code></p>

<p>The result of <code>number.toExponential();</code> is <code class="output9"></code></p>

<p>The result of <code>number.toExponential(1);</code> is <code class="output10"></code></p>

<p>The result of <code>number.toExponential(2);</code> is <code class="output11"></code></p>
  
  <h2>Try for yourself</h2>
  <input id="tryNum" type="text"><code>.toExponential(</code><input id="tryArg" type="text"><code>)</code> returns <code id="tryOutput"></code>
  
</div>
              
            
!

CSS

              
                body { 
  font-family: sans-serif;
  background-color: rgb(29, 31, 32);
  color: #fff;
  font-size: 1.6em;
  margin-left: 24px;
}
p {
  margin-bottom: 12px;
  color: #fff;
}
input {
  color: #000;
}
              
            
!

JS

              
                var num = new Number(9234.4354);
    $('.output1').html(num);

var num2 = num.toExponential();
    $('.output2').html(num2);

var num3 = num.toExponential(1);
    $('.output3').html(num3);

var num4 = num.toExponential(2);
    $('.output4').html(num4);

var num5 = num.toExponential(10);
    $('.output5').html(num5);

//var num6 = num.toExponential(-2);
   // $('.output6').html(num6);

var num7 = num.toExponential(0);
    $('.output7').html(num7);


var number = 852.46;
    $('.output8').html(number);

var number9 = number.toExponential();
    $('.output9').html(number9);

var number10 = number.toExponential(1);
    $('.output10').html(number10);

var number11 = number.toExponential(2);
    $('.output11').html(number11);

$('#tryNum, #tryArg').on('keyup change', function(){
  var tryNum = parseFloat($('#tryNum').val(), 10);
  var tryArg = parseInt($('#tryArg').val(), 10);
  var result;
  if (tryArg) {
    try {
      result = tryNum.toExponential(tryArg);
    } catch(e) {
      result = 'Error: ' + e.message;
    }
  } else {
    try { result = tryNum.toExponential();
    } catch(e) {
      result = 'Error: ' + e.message;
    }
  }
  //var result = tryArg ? tryNum.toExponential(tryArg) : tryNum.toExponential();
  $('#tryOutput').html(result);
});

              
            
!
999px

Console