Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

86 lines (71 sloc) 4.54 KB
<!DOCTYPE html>
<html data-require="math math-format">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Scientific notation</title>
<script data-main="../local-only/main.js" src="../local-only/require.js"></script>
<div class="exercise">
<div class="vars" data-ensure="NUMBER_SEED % 10 !== 0">
<var id="NUMBER_SEED">randRange(100, 9999)</var>
<var id="NUMBER_SEED_LENGTH">NUMBER_SEED.toString().length</var>
<var id="ZEROES">rand(2) === 0 ? randRange(4, 8) : randRange( -1 * NUMBER_SEED_LENGTH - 4, -1 * NUMBER_SEED_LENGTH )</var>
<var id="E">ZEROES + ( NUMBER_SEED_LENGTH - 1 )</var>
<var id="BASE">NUMBER_SEED / pow( 10, E - ZEROES )</var>
<var id="BASE_STR">localeToFixed(BASE, E - ZEROES)</var>
<var id="LEADING">floor( BASE )</var>
<var id="TRAIL">BASE_STR.substring( 1 )</var>
<var id="DECIMAL">
ZEROES &gt; 0 ?
NUMBER_SEED * pow( 10, ZEROES ) :
// NOTE: Don't use toFixed unless you have a good reason,
// use localeToFixed instead. Here, since we're passing off
// to commafy, we need toFixed.
(NUMBER_SEED * pow( 10, ZEROES )).toFixed(-1 * ZEROES)
<var id="PRETTY_DECIMAL">commafy( DECIMAL )</var>
<var id="SCIENTIFIC">BASE_STR + " \\times 10^{" + E + "}"</var>
<div class="problems">
<p class="question">
Express this number in scientific notation.
<p class="problem"><code><var>PRETTY_DECIMAL</var></code></p>
<div class="solution" data-type="multiple">
<span class="sol base short40" data-forms="integer, decimal"><var>BASE</var></span>
<code> \times 10 </code>
<sup class="sol exp short20" data-forms="integer, decimal"><var>E</var></sup>
<div class="hints">
<div class="digits" data-unwrap="">
<p data-if="E > 0">There are <code>\exponentColor{<var>E</var>}</code> digits to the right of the leading <code>\leadingColor{<var>LEADING</var>}</code> (and to the left of the decimal).</p>
<div data-else="" data-unwrap="">
<p>Count the zeroes to the right of the decimal point before the leading <code>\leadingColor{<var>LEADING</var>}</code>: there <span data-if="E + 1 === -1">is 1 zero</span><span data-else="">are <code><var>(E + 1) * -1</var></code> zeroes</span>.</p>
<p data-if="E === -1">If you count the leading digit <code>\leadingColor{<var>LEADING</var>}</code><span data-if="E + 1 < -1"> and those zeroes</span><span data-else-if="E + 1 === -1"> and the 1 zero</span>, there is <code>\exponentColor{<var>E * -1</var>}</code> digit to the <span style="color: purple;">right</span> of the decimal point.</p><p data-else="">If you count the leading digit <code>\leadingColor{<var>LEADING</var>}</code><span data-if="E + 1 < -1"> and those zeroes</span><span data-else-if="E + 1 === -1"> and the 1 zero</span>, there are <code>\exponentColor{<var>E * -1</var>}</code> digits to the <span style="color: purple;">right</span> of the decimal point.</p>
<p class="answer">So: <code><var>PRETTY_DECIMAL</var> = \leadingColor{<var>LEADING</var>}<var>TRAIL</var> \times 10^{\exponentColor{<var>E</var>}}</code></p>
<div class="vars">
<var id="TEN_POWER">commafy( pow( 10, E ) )</var>
<p class="question"><code><var>SCIENTIFIC</var> = {?}</code></p>
<p class="solution"><var>DECIMAL</var></p>
<div class="hints">
<p class="digits"><code><var>SCIENTIFIC</var> = <var>BASE_STR</var> \times <var>TEN_POWER</var></code></p>
<p class="answer"><code><var>BASE_STR</var> \times <var>TEN_POWER</var> = <var>PRETTY_DECIMAL</var></code></p>
<div class="hints">
<p class="digits"></p>
<p class="answer"></p>
Jump to Line
Something went wrong with that request. Please try again.