Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: Is this correct way to describe fractions(decimals) in different bases?
Replies: 0

 JT Posts: 1,448 Registered: 4/7/12
Is this correct way to describe fractions(decimals) in different bases?
Posted: Jan 31, 2013 10:58 PM

Copy to textfile with extension HTML and run by doubleclick.

<META http-equiv=Content-Type content="text/html;
charset=windows-1252">
<SCRIPT language=Javascript>
function anybase() {

fullnumber=document.doit.dnumb.value;
twoparts = fullnumber.split(",");
bas=document.doit.bval.value;

for(j=0;j<2;j++){
btwo=1;
bnr=0;
unr=0;

decimalnumber=twoparts[j];

while (btwo<decimalnumber){
btwo=btwo*bas;
bnr++
}
basestring="";
while (decimalnumber>0){
unr++;
set=0;
for(i=bas;i>0;i--){
st=btwo*i;
if (decimalnumber>=st) {
decimalnumber=decimalnumber-st;
set=1;
basestring=basestring+i+",";
}
}
if(set==0 && decimalnumber!=0)basestring=basestring+0+",";
btwo=btwo/bas;
}
while (bnr>=unr){
basestring=basestring+0+",";
unr++;
}
}

controldec=document.doit.fracted.value;
show=document.doit.dnumb.value+"=";
//Control Radix by go back to decimal
darr = control.split(",");
decarr = controldec.split(",");
darr.reverse();
decarr.reverse();

total=0;
totalfrac=0;
multiple=1
for (i=1;i<darr.length;i++){
cval=darr[i];
cval=cval*multiple;
total=total+cval;
show=show+"("+multiple+"*"+darr[i]+")+";
multiple=bas*multiple;
}

multiple=1
for (i=1;i<decarr.length;i++){
cval=decarr[i];
cval=cval*multiple;
totalfrac=totalfrac+cval;
show=show+"("+multiple+"*"+decarr[i]+")+";
multiple=bas*multiple;
}
totalfull=total+","+totalfrac;
document.doit.controlout.value=totalfull;
document.doit.overview.value=show;
}

</SCRIPT>
<HTML><BODY>
<FORM NAME=doit onSubmit="anybase(); return false;">
CHANGE BASE:
<input type=submit value="GO!"><P>
DECIMAL VALUE:<TEXTAREA NAME=dnumb COLS=30
ROWS=1>777777777777,3333333</TEXTAREA><BR>
BASE:<TEXTAREA NAME=bval COLS=30
ROWS=1>333</TEXTAREA><BR>
ROWS=1></TEXTAREA><BR>
FRACTION OUT:<TEXTAREA NAME=fracted COLS=200
ROWS=1></TEXTAREA><BR>

BACK TO DECIMAL CONTROL CONVERSION->
<TEXTAREA NAME=controlout COLS=30
ROWS=1></TEXTAREA><BR>