# rcourtie/khan-exercises forked from Khan/khan-exercises

Fetching contributors…
Cannot retrieve contributors at this time
64 lines (56 sloc) 2.51 KB
 Changing decimals to fractions 2
randRange( 0, 1 ) ? randRange( 100, 999 ) : randRange( 1000, 9999 ) ( NUMERATOR / 10000 ).toFixed( 4 )

Express D as a fraction.

D

D can be represented as follows.

= 0 + fraction( D.substr( 2, 1 ) , 10 ) + fraction( D.substr( 3, 1 ) , 100 ) + fraction( D.substr( 4, 1 ), 1000 ) + fraction( D.substr( 5, 1 ), 10000 )

= fraction( NUMERATOR, 10000 )

You can also skip a few steps by making a fraction with NUMERATOR as the numerator and 10000 (because the decimal extends to the ten thousandths place) as the denominator.

fraction( NUMERATOR, 10000 )

randRange( 1, 19 ) randRangeExclude(1, 99, [ 10 , 20 , 30 , 40 , 50 , 60 , 70 , 80 , 90 ]) / 100 getGCD( round( D * 100 ) , 100 ) ( W + D ).toFixed( 2 )

Express FIXED as a mixed number. Reduce to lowest terms.

W + D

FIXED can be represented as follows:

= W + fraction( floor( D * 10 ), 10 ) + fraction( floor( ( D * 100 ) % 10 ), 100 )

= W + fraction( roundTo( 0, D * 100 ), 100 )

Reduce the fractional part by dividing the numerator and denominator by GCD.

=W + fractionReduce( round( D * 100 ) , 100 )