shuffle( [1, 2, 3, 4, 5, 6, 7, 8, 9], 5 )
+DIGITS.join( "" )
randFromArray([ -2, -3 ])
placesLeftOfDecimal[ -PLACE ]
roundTo( PLACE, NUM )
Round commafy( NUM )
to the nearest TPLACE.
ROUNDED
randFromArray([ -2, -3 ])
(function() {
var digits = shuffle( [1, 2, 3, 4, 6, 7, 8, 9], 5 )
digits[ 5 + PLACE ] = 5;
return digits;
})()
+DIGITS.join( "" )
placesLeftOfDecimal[ -PLACE ]
roundTo( PLACE, NUM )
Round commafy( NUM )
to the nearest TPLACE.
ROUNDED
There are two ways to think about this problem.
1st way: Look at the placesLeftOfDecimal[ -1 - PLACE ]s digit DIGITS[ 5 + PLACE ]
to see whether to round up or down.
Because it is more thanequal to 5
, we round up, giving commafy( ROUNDED )
.
Because it is less than 5
, we round down, giving commafy( ROUNDED )
.
2nd way: Consider which end of the number line is closer to NUM - this end is circled in blue.
init({
range: [ [ -0.06 * pow( 10, -PLACE ) , 1.3 * pow( 10, -PLACE ) ], [-1, 1] ],
scale: [ 600 * pow( 10, PLACE ), 40 ]
});
numberLine( floorTo( PLACE , NUM ), ceilTo( PLACE , NUM ) + pow( 10, -( PLACE+2 )) , round( pow( 10, -(PLACE + 1 ))) );
style({ stroke: "#FFA500", fill: "#FFA500", strokeWidth: 3.5 });
ellipse( [ 10 * pow( 10, -( PLACE+1 )) * (NUM - floorTo( PLACE , NUM ))/pow( 10,- (PLACE) ), 0 ], [pow( 10, -PLACE ) / 100, 0.15]);
label( [ 10 * pow(10, -( PLACE+1 )) * ( NUM - floorTo( PLACE , NUM ))/pow( 10,- (PLACE) )], NUM, "below");
style({ stroke: "#6495ED", "fill": "none", strokeWidth: 3.5 });
if( DIGITS[ 5 + PLACE ] >= 5 ) {
ellipse( [ pow( 10, -PLACE ), -0.55 ], [pow( 10, - PLACE - 0.5 ) / 6.5, 0.35] );
} else {
ellipse( [ 0, -0.55 ], [pow( 10, - PLACE - 0.5 ) / 6.5, 0.35] );
}