Permalink
Fetching contributors…
Cannot retrieve contributors at this time
126 lines (105 sloc) 6.07 KB
<!DOCTYPE html>
<html data-require="math math-format graphie graphie-helpers-arithmetic">
<head>
<meta charset="UTF-8">
<title>Understanding moving the decimal</title>
<script data-main="../local-only/main.js" src="../local-only/require.js"></script>
</head>
<body>
<div class="exercise">
<div class="vars">
<var id="PM">randRangeNonZero( -1, 1 )</var>
<var id="OPERATOR">( PM === 1 ? i18n._("multiply") : i18n._("divide") )</var>
<var id="A">randRange( 0, 99999 )</var>
<div data-ensure="( PM === 1 ? A_DECIMAL &gt; B_DECIMAL : A_DECIMAL &lt; B_DECIMAL )">
<var id="A_DECIMAL">randRange( 1, 5 )</var>
<var id="B_DECIMAL">randRange( 1, 5 )</var>
</div>
<var id="A_FLOAT">A / pow( 10, A_DECIMAL )</var>
<var id="B_FLOAT">A / pow( 10, B_DECIMAL )</var>
<var id="POW_DIFF">( PM === 1 ? ( A_DECIMAL - B_DECIMAL ) : ( B_DECIMAL - A_DECIMAL ) )</var>
</div>
<div class="problems">
<div>
<div class="question">
<p data-if="PM === 1">
<b>How many times do you need to multiply <code><var>localeToFixed(A_FLOAT, A_DECIMAL)</var></code> by ten to get <code><var>localeToFixed(B_FLOAT, B_DECIMAL)</var></code>?</b>
</p><p data-else>
<b>How many times do you need to divide <code><var>localeToFixed(A_FLOAT, A_DECIMAL)</var></code> by ten to get <code><var>localeToFixed(B_FLOAT, B_DECIMAL)</var></code>?</b>
</p>
</div>
<p class="solution" data-forms="integer"><var>POW_DIFF</var></p>
</div>
</div>
<div class="hints">
<div class="graphie">
init({
range: [ [ -1, 11 ], [ -1, 3 ] ],
scale: [20, 40]
});
var digitsA = KhanUtil.digits( A );
//Pad zeroes if need be for the decimal point
while ( digitsA.length &lt; A_DECIMAL + 1) {
digitsA.push( 0 );
}
var digitsB = digitsA.slice();
//For the leading zero 0.# only occurs with division
if ( digitsA.length &lt; B_DECIMAL + 1) {
digitsA.push( ' ' );
digitsB.push( 0 );
}
drawDigits( digitsA.reverse(), 0, 1);
drawDigits( digitsB.reverse(), 0, 0);
for ( var i = 0; i &lt; POW_DIFF; i++) {
if ( PM === 1 ) {
arc( [ digitsA.length - A_DECIMAL + i, 1.5 ], 0.5, 0, 180, { stroke: "blue" } );
label( [ digitsA.length - A_DECIMAL + i, 2 ], i+1, "above" );
if ( i === POW_DIFF - 1 ) {
//hack for the final arrow...is there a better way?
line( [ digitsA.length - A_DECIMAL + i + 0.5, 1.5 ], [ digitsA.length - A_DECIMAL + i + 0.5, 1.46 ], { stroke: "blue", arrows: "-&gt;" } );
}
}
else {
//to draw the final arrow
if ( i === POW_DIFF - 1 ) {
style({ arrows: "-&gt;" });
}
arc( [ digitsA.length - A_DECIMAL - (i + 1), 1.5 ], 0.5, 0, 180, { stroke: "blue" } );
label( [ digitsA.length - A_DECIMAL - (i + 1), 2 ], i+1, "above" );
}
}
//draw a black ellipse to be used as a decimal point
style({ fill: "#000" });
ellipse( [ digitsA.length - A_DECIMAL - 0.5, 0.8 ], [ 0.09, 0.06 ] );
ellipse( [ digitsB.length - B_DECIMAL - 0.5, -0.2 ], [ 0.09, 0.06 ] );
var labelstr = "The decimal point needs to be moved " + POW_DIFF + " time" + ( POW_DIFF !== 1 ? "s." : ".");
label ([ digitsA.length + 0.5, 0.5 ], labelstr, "right", false);
</div>
<p data-if="PM === 1">Moving the decimal one position to the right is the same as multiplying by ten once.</p><p data-else="">Moving the decimal one position to the left is the same as dividing by ten once.</p>
<div data-if="PM === 1 && POW_DIFF !== 1">
<p data-if="POW_DIFF !== 1">Thus, moving the decimal right <code><var>POW_DIFF</var></code> times is the same as multiplying by ten <code><var>POW_DIFF</var></code> times, or multiplying by <code><var>pow( 10, POW_DIFF )</var></code>:</p>
<p><code>{<var>localeToFixed(A_FLOAT, A_DECIMAL)</var>} * {<var>pow( 10, POW_DIFF )</var>} = {<var>localeToFixed(B_FLOAT, B_DECIMAL)</var>}</code></p>
</div>
<div data-if="PM !== 1 && POW_DIFF !== 1">
<p data-if="POW_DIFF !== 1">Thus, moving the decimal left <code><var>POW_DIFF</var></code> times is the same as dividing by ten <code><var>POW_DIFF</var></code> times, or dividing by <code><var>pow( 10, POW_DIFF )</var></code>:</p>
<p><code>{<var>localeToFixed(A_FLOAT, A_DECIMAL)</var>} \div {<var>pow( 10, POW_DIFF )</var>} = {<var>localeToFixed(B_FLOAT, B_DECIMAL)</var>}</code></p>
</div>
<div>
<p data-if="PM === 1">
<span data-if="POW_DIFF === 1">
<b>You need to multiply by ten <code><var>POW_DIFF</var></code> time.</b>
</span><span data-else>
<b>You need to multiply by ten <code><var>POW_DIFF</var></code> times.</b>
</span>
</p><p data-else>
<span data-if="POW_DIFF === 1">
<b>You need to divide by ten <code><var>POW_DIFF</var></code> time.</b>
</span><span data-else>
<b>You need to divide by ten <code><var>POW_DIFF</var></code> times.</b>
</span>
</p>
</div>
</div>
</div>
</body>
</html>