I make miniatures, and many times I use full size plans as guides to make these miniatures, by converting the full size dimensions to a convenient scale dimension. Unfortunately it currently takes several steps and several calculators to do the job. [URL=http://zooplies.com/Miniature_Haven/Custom_Tools/F_scale_converter.shtml]Current Calculators
I was wondering if it is possible to make a script calculator that would automatically (with options provided by the user) convert a full size dimension to the scale dimension, providing the answer in its simplest form – whether the user wants it in decimal, fractional, or metric measurements.
For example – I have a plan that requires slates for a chair that are 1/2″ x 1+1⁄2″ x 17+3⁄8″ (thickness, width, length in inches) and I need to convert them to 1:12 scale (1 inch = 1 foot) I have a friend that needs to convert to 1:6 scale (1 inch = 6 inches) and another friend that needs 1:24 scale (1 inch = 2 feet)
I currently use a calculator that converts to scale, providing answers in decimal form (in 1:12 scale) – 1/2″ x 1+1⁄2″ x 17+3⁄8″ would equal
0.041666666666666664” x 0.125” x 1.4479166666666667”
I then input into these answers into another calculator that converts to fractions (I provide the level of accuracy needed, i.e. the nearest 96th of an inch) thank you [B][COLOR=Red]tabzter
4/96” x 12/96” x 1+43/96”
Finally I convert these to their simplest form –
1/24” x 1/8” x 1+43/96”
Ideally I would like a calculator that could:
[list=1][*]
Provide the Scale Needed (any numerical scale entered – saved until changed)
Choose the Final Output in Simplest Form – i.e. Fraction, Decimal, Metric (selectable buttons that remain activated until changed)
Provide the level of accuracy needed – i.e. the closest 1/8th in., 1/16th in., 1/96th in., or number of decimal points for the final solution, etc. (selectable buttons for fractions or #of decimal places – that remain activated until changed)
Where I can put all three dimensions in at once – i.e. Thickness, Width, Length
And with a push of a single button – get the final answer, without NaN showing up when a leading 0 is not provided.
I believe this is possible (especially with this group) but I haven’t been able to find a script like this anywhere – and I’ve searched for weeks.
Any Help would be appreciated and both credit and links will be provided when placed on my web page.
Thank You
ArchAngle @ [URL=http://www.zooplies.com]Zooplies
[CODE]<script>
<!-- Activate Cloaking Device
//***************************************************************************
// This Javascript was adapted from
// Formatting Money Values
// by Tim Wallace ([email protected])
//***************************************************************************
function compute()
{
if (document.forms[0].inunit.value==document.forms[0].outunit.value) {
var partA= eval(document.forms[0].input.value)/(document.forms[0].scale.value);
document.forms[0].output.value=partA;
} else {
if (document.forms[0].inunit.value=="inches") {
var partA= eval(document.forms[0].input.value)/(document.forms[0].scale.value);
document.forms[0].output.value=partA*2.54;
} else {
var partA= eval(document.forms[0].input.value)/(document.forms[0].scale.value);
document.forms[0].output.value=partA/2.54;
}
}
}
function unit1()
{
document.forms[0].inunit.value="centimeters";
compute();
}
function unit2()
{
document.forms[0].inunit.value="inches";
compute();
}
function unit3()
{
document.forms[0].outunit.value="centimeters";
compute();
}
function unit4()
{
document.forms[0].outunit.value="inches";
compute();
}
// Called by Reset button - sets original values.
function resetIt()
{
document.forms[0].scale.value="6";
document.forms[0].input.value="10";
document.forms[0].output.value="";
document.forms[0].inunit.value="inches";
document.forms[0].outunit.value="inches";
}
// Called by About button - info on example.
function about()
{
alert("nJavascript adapted by Jimbob 5/99 from "Formatting Money Values"n by Tim Wallace ([email protected]).n");
}
function computeb()
{
if (document.forms[0].inunitb.value==document.forms[0].outunitb.value) {
var partAb= eval(document.forms[0].inputb.value)*(document.forms[0].scaleb.value);
document.forms[0].outputb.value=partAb;
} else {
if (document.forms[0].inunitb.value=="inches") {
var partAb= eval(document.forms[0].inputb.value)*(document.forms[0].scaleb.value);
document.forms[0].outputb.value=partAb*2.54;
} else {
var partAb= eval(document.forms[0].inputb.value)*(document.forms[0].scaleb.value);
document.forms[0].outputb.value=partAb/2.54;
}
}
}
function unit1b()
{
document.forms[0].inunitb.value="centimeters";
computeb();
}
function unit2b()
{
document.forms[0].inunitb.value="inches";
computeb();
}
function unit3b()
{
document.forms[0].outunitb.value="centimeters";
computeb();
}
function unit4b()
{
document.forms[0].outunitb.value="inches";
computeb();
}
function scaleupdown()
{
computeb();
document.forms[0].inunit.value=document.forms[0].outunitb.value;
document.forms[0].input.value= document.forms[0].outputb.value;
compute();
}
// Deactivate Cloaking -->
</script>[/CODE]
[CODE]
<script type="text/javascript">
var primValue = document.getElementById("primary");
var secValue = document.getElementById("secondary");
document.getElementById("convert").onclick = function() {
var answer = document.getElementById("answer");
if (secValue.value == "") {
answer.firstChild.data = "No Scale Factor Entered: Please Try Again";
} else
if (primValue.value.match(/^d*.?d*$/)) {
var integer = parseInt(primValue.value.match(/^d*.?/)[0]);
var decimal = parseFloat("0"+primValue.value.match(/.d*$/)[0]);
var rationalise = Math.round(secValue.value*decimal);
answer.innerHTML = integer+"<sup>"+rationalise+"</sup>/<sub>"+secValue.value+"</sub>";
} else {
answer.firstChild.data = "Wrong Number Format Entered: Please Try Again";
}
};
</script>
<div id="answer" style="border:2px solid green; font-family:courier new, arial; font-size:1.3em; height:40px; width:112px">
Answer Here</div>[/CODE]
[code=html]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE>Scale Conversion Tool - Decimal to Fraction Tool</TITLE>
<SCRIPT>
<!--
function Calculate(value, acc)
{
if (value.match(/^d*.?d*$/)) {
var integer = parseInt(value.match(/^d*.?/)[0]);
var decimal = parseFloat("0"+value.match(/.d*$/)[0]);
var rationalise = Math.round(acc*decimal);
return integer+"<sup>"+rationalise+"</sup>/<sub>"+acc+"</sub>";
} else {
return "Wrong Number Format Entered: Please Try Again";
}
}
function frac()
{
var valuex = document.forms[0].outputx.value
var valuey = document.forms[0].outputy.value
var valuez = document.forms[0].outputz.value
var acc = document.forms[0].accuracy.value
var answerx = document.getElementById("answerx");
var answery = document.getElementById("answery");
var answerz = document.getElementById("answerz");
if (acc == "")
{
alert("No Accuracy Entered: Please Try Again")
}
else
{
answerx.innerHTML = Calculate(valuex,acc)
answery.innerHTML = Calculate(valuey,acc)
answerz.innerHTML = Calculate(valuez,acc)
}
}
function compute()
{
if (document.forms[0].inunit.value==document.forms[0].outunit.value)
{
var partA = eval(document.forms[0].inputx.value)/(document.forms[0].scale.value);
document.forms[0].outputx.value=partA;
partA = eval(document.forms[0].inputy.value)/(document.forms[0].scale.value);
document.forms[0].outputy.value=partA;
partA = eval(document.forms[0].inputz.value)/(document.forms[0].scale.value);
document.forms[0].outputz.value=partA;
}
else
{
if (document.forms[0].inunit.value=="inches")
{
var partA= eval(document.forms[0].inputx.value)/(document.forms[0].scale.value)
document.forms[0].outputx.value=partA*2.54
partA= eval(document.forms[0].inputy.value)/(document.forms[0].scale.value)
document.forms[0].outputy.value=partA*2.54
partA= eval(document.forms[0].inputz.value)/(document.forms[0].scale.value)
document.forms[0].outputz.value=partA*2.54
}
else
{
var partA= eval(document.forms[0].inputx.value)/(document.forms[0].scale.value
)
document.forms[0].outputx.value=partA/2.54
partA= eval(document.forms[0].inputy.value)/(document.forms[0].scale.value)
document.forms[0].outputy.value=partA/2.54
partA= eval(document.forms[0].inputz.value)/(document.forms[0].scale.value)
document.forms[0].outputz.value=partA/2.54
}
}
frac()
}
function unit1()
{
document.forms[0].inunit.value="centimeters";
compute();
}
function unit2()
{
document.forms[0].inunit.value="inches";
compute();
}
function unit3()
{
document.forms[0].outunit.value="centimeters";
compute();
}
function unit4()
{
document.forms[0].outunit.value="inches";
compute();
}
// Called by Reset button - sets original values.
function resetIt()
{
document.forms[0].scale.value="6";
document.forms[0].input.value="10";
document.forms[0].output.value="";
document.forms[0].inunit.value="inches";
document.forms[0].outunit.value="inches";
}
-->
</SCRIPT>
</FONT></P>
<H2 class=producthdr align=center><FONT face=Verdana
color=#2271a0 size=4>SCALE CONVERSION
CALCULATOR<BR></FONT></H2>
<FORM>
<TABLE id=table10 cellPadding=3 width=619
bgColor=#ffffff border=2>
<TBODY>
<TR>
<TD align=middle><FONT
face=Verdana><STRONG>Scale</STRONG> </FONT><br/>
<FONT
face=Verdana><STRONG>Accuracy</STRONG></FONT></TD>
<TD align=middle colSpan=4><FONT
face=Verdana><STRONG>1:</STRONG></FONT><INPUT
size=10 value=12 name='scale'> <br/>
<INPUT
size=10 name='accuracy'> </TD>
<TD align=left width=263 rowSpan=3>
<CENTER><FONT face=Verdana><B>SCALE
DOWN</B></FONT></CENTER><FONT
face=Verdana><BR> </FONT>
<UL>
<LI>To enter the scaling factor; for 1/24th
scale, enter a '24'; for 1/144th scale, enter a
'144', for 1/12th scale enter a 12, (the
default)
<LI><FONT face=Verdana>In the box marked
"input", enter the measurement of a real-world
object in either inches or centimeters (see
<B><A
href="http://zooplies.com/Miniature_Haven/Custom_Tools/F_scale_converter.shtml#frac">*below</A></B>
for entering fractions) </FONT>
<LI><FONT face=Verdana>Press the button labeled
"in" (inches) or "cm" (centimeter) </FONT>
<LI><FONT face=Verdana>The scaled down size of
that object is displayed in the box marked
"output" </FONT>
<LI><FONT face=Verdana>Pressing the "in" or "cm"
output button will cause the results to be
recalculated and displayed in the unit of
measure you've selected. </FONT></LI></UL></TD></TR>
<TR>
<TD align=middle><FONT
face=Verdana><STRONG>Input</STRONG> </FONT></TD>
<TD align=middle>
x:
<INPUT size=10 name=inputx>
y: <INPUT size=10 name=inputy>
z: <INPUT size=10 name=inputz>
</TD>
<TD align=middle><INPUT size=10 value=inches
name=inunit> </TD>
<TD align=middle><INPUT onclick=unit1() type=button value=cm>
</TD>
<TD align=middle><INPUT onclick=unit2() type=button value=in>
</TD></TR>
<TR>
<TD align=middle><FONT
face=Verdana><STRONG>Output</STRONG> </FONT></TD>
<TD align=middle>
x:
<INPUT size=10 name=outputx><br/>
<div id=answerx
style="border:solid black 1px; width: 112px;height: 40px"></div>
y:
<INPUT size=10 name=outputy><br/>
<div id=answery
style="border:solid black 1px; width: 112px;height: 40px"></div>
z:
<INPUT size=10 name=outputz><br/>
<div id=answerz
style="border:solid black 1px; width: 112px;height: 40px"></div>
</TD>
<TD align=middle><INPUT size=10 value=inches
name=outunit> </TD>
<TD align=middle><INPUT onclick=unit3() type=button value=cm>
</TD>
<TD align=middle><INPUT onclick=unit4() type=button value=in>
</TD></TR></TBODY></TABLE><SPAN
style="FONT-SIZE: 9pt"><BR><BR><B><A name=frac>*Entering
Fractions:</A></B> If you want to find out the decimal
inch for a fraction, simply enter a fraction,
1/32, 1/2, 95/96 . If you input a mixed measure like
"12-1/2" instead of "12.5", it evaluates the expression
as "12 minus 1 divided by 2", the result of which is
"11.5". Therefore, you can enter fractional inches if
you input the value as <B>"12+1/2"</B> (using a
"<B>plus</B>" instead of the "minus"). The expression
will be evaluated as a decimal value. However, if you
input the measure as "12 1/2" (without the "plus" or
"minus" operator) you will cause a JavaScript error! You
can however enter something like (5*12)+4+(3/4), which
is like saying "five feet four and three-quarter inches"
(5 feet times 12 inches plus 4 inches plus 3/4 of an
inch). NOTE! The calculator doesn't under stand
Feet - it requires it to be converted into inches, like
above. The same would hold true for Meters and
centimeters!</SPAN>
<P class=producthdr>"*" = times (multiply),
"/" = divide, "+" = plus, "-" =
minus.</P></FORM></TD></TR></TBODY></TABLE>
[/code]
[CODE]<FORM>
<div align="center"><TABLE id=table2 cellPadding=3 width=619
bgColor=#ffffff border=2>
<TBODY>
<TR>
<TD align=middle><FONT face=Verdana><font color="#FF0000"><STRONG>Scale</STRONG></font> <br>
</FONT><br/>
<FONT
face=Verdana color="#FF0000"><STRONG>Accuracy</STRONG></FONT></TD>
<TD align=middle colSpan=4>
<FONT face=Verdana><STRONG><font size="3"> 1:</font></STRONG></FONT><INPUT
size=4 value=12 name='scale'><br>
To Nearest <font size="3">=</font>
<INPUT
size=4 value="96 " name='accuracy' style="text-align: right"><sup>th </sup>
inch</TD>
<TD align=left width=263 rowSpan=3>
<CENTER><FONT face=Verdana><B>SCALE
DOWN</B></FONT></CENTER>
<UL>
<LI>To enter the scaling factor other than 1/12<sup>th</sup>,
highlight the default 12 and enter whatever scale you want; 24 for 1/24th scale; 144 for 1/144th scale; etc..
<LI>Next enter the level of accuracy you want.
To the nearest 24<sup>th</sup> inch, 48<sup>th</sup>
inch, etc.. (Read<b>
<a href="http://zooplies.com/Miniature_Haven/Custom_Tools/F_scale_converter.shtml#Caution:">
Caution</a></b>)<LI>In the boxes marked "<b><font color="#FF0000">input</font></b>",
enter the measurement of a real-world object in
either inches or centimeters (Read
<a href="http://zooplies.com/Miniature_Haven/Custom_Tools/F_scale_converter.shtml#frac">
<b>Fractions</b></a>)
<LI>Press <INPUT onclick=unit2() type=button value=in> button
for inches<br>
or <INPUT onclick=unit1() type=button value=cm>
button for centimeter
<LI>The scaled size of
that object is displayed in the boxes marked
"<b><font color="#FF0000">output</font></b>"
<LI>Your Answers will be displayed in both
decimal
and common fraction.</LI></UL></TD></TR>
<TR>
<TD align=middle><FONT
face=Verdana><STRONG><font color="#FF0000">Input</font>
in Inches, Centimeters or Millimeters only
</STRONG> </FONT></TD>
<TD align=middle>
x: <INPUT size=10 name=inputx><br>
y: <INPUT size=10 name=inputy><br>
z: <INPUT size=10 name=inputz></TD>
<TD align=middle><INPUT size=10 value=inches
name=inunit> </TD>
<TD align=middle><INPUT onclick=unit1() type=button value=cm>
</TD>
<TD align=middle><INPUT onclick=unit2() type=button value=in>
</TD></TR>
<TR>
<TD align=middle><FONT face=Verdana><STRONG><font color="#FF0000">Output</font>
in Decimal & Common Fractions</STRONG> </FONT></TD>
<TD align=middle>
x:
<INPUT size=10 name=outputx><br/>
<div id=answerx
style="border:solid black 1px; width: 112px;height: 40px"></div>
y:
<INPUT size=10 name=outputy><br/>
<div id=answery
style="border:solid black 1px; width: 112px;height: 40px"></div>
z:
<INPUT size=10 name=outputz><br/>
<div id=answerz
style="border:solid black 1px; width: 112px;height: 40px"></div>
</TD>
<TD align=middle><INPUT size=10 value=inches
name=outunit> </TD>
<TD align=middle><INPUT onclick=unit3() type=button value=cm>
</TD>
<TD align=middle><INPUT onclick=unit4() type=button value=in>
</TD></TR></TBODY></TABLE></div>
<BR><BR><B><a name="frac">Fractions:</a></B> When
entering numbers, make sure you're using only inches
and/or fractions, and enter them in a form the computer
will understands. i.e. If you input a mixed
measure like "<b>12-1/2</b>" the computer will evaluate
the expression as "<b>12</b> minus <b>1</b> divided by
<b>2</b>", the result of which is "<b>11.5</b>". You
must enter the expression the computer understands.
i.e. <B>"12+1/2"</B> (using a "<B>plus</B>" instead of the "minus") or as <b>12.5</b>".
<SPAN
style="font-weight:700">The same would hold true for
centimeters and millimeters!</SPAN><br>
<br>
<b><font color="#FF0000">NEVER </font></b>input the
measure as "<b>12 1/2</b>" (without the "plus" or
"minus" operator) this will cause a JavaScript error!
<font color="#FF0000"><b><br>
<br>
NOTE!</b></font> This calculator doesn't understand Feet
or Meters - it requires them to be converted into
inches/centimeters. You can however enter
something like (5*12)+4+(3/4), which is like saying
"five feet four and three-quarter inches" (5 feet times
12 inches plus 4 inches plus 3/4 of an inch).
Computer understands that "*" = multiply,
"/" = divide, "+" = plus, "-" =
minus.<b><br>
<br>
<a name="Caution:">Caution:</a></b> Entering a
small level of accuracy can adversely affect your
results - the computer will always round to the nearest
scale factor. i.e. you enter a scale factor of 12,
and an accuracy of 12. This means that you are
only getting accuracy to the nearest inch for the scale
model, which means that if you need an item 3+1/2 inches
you'll get a scale result of 4/12 - which is really 4
inches. The decimal fraction displayed will be
correct and isn't affected by the accuracy level.</FORM></TD>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE>Scale Conversion Tool - Decimal to Fraction Tool</TITLE>
<SCRIPT>
<!--
function Calculate(value, acc)
{
if (value.match(/^d*.?d*$/)) {
var integer = parseInt(value.match(/^d*.?/)[0]);
var decimal = parseFloat("0"+value.match(/.d*$/)[0]);
var rationalise = Math.round(acc*decimal);
return integer+"<sup>"+rationalise+"</sup>/<sub>"+acc+"</sub>";
} else {
return "Wrong Number Format Entered: Please Try Again";
}
}
function frac()
{
var valuex = document.forms[0].outputx.value
var valuey = document.forms[0].outputy.value
var valuez = document.forms[0].outputz.value
var acc = document.forms[0].accuracy.value
var answerx = document.getElementById("answerx");
var answery = document.getElementById("answery");
var answerz = document.getElementById("answerz");
if (acc == "")
{
alert("No Accuracy Entered: Please Try Again")
}
else
{
answerx.innerHTML = Calculate(valuex,acc)
answery.innerHTML = Calculate(valuey,acc)
answerz.innerHTML = Calculate(valuez,acc)
}
}
function compute()
{
if (document.forms[0].inunit.value==document.forms[0].outunit.value)
{
var partA = eval(document.forms[0].inputx.value)/(document.forms[0].scale.value);
document.forms[0].outputx.value=partA;
partA = eval(document.forms[0].inputy.value)/(document.forms[0].scale.value);
document.forms[0].outputy.value=partA;
partA = eval(document.forms[0].inputz.value)/(document.forms[0].scale.value);
document.forms[0].outputz.value=partA;
}
else
{
if (document.forms[0].inunit.value=="inches")
{
var partA= eval(document.forms[0].inputx.value)/(document.forms[0].scale.value)
document.forms[0].outputx.value=partA*2.54
partA= eval(document.forms[0].inputy.value)/(document.forms[0].scale.value)
document.forms[0].outputy.value=partA*2.54
partA= eval(document.forms[0].inputz.value)/(document.forms[0].scale.value)
document.forms[0].outputz.value=partA*2.54
}
else
{
var partA= eval(document.forms[0].inputx.value)/(document.forms[0].scale.value
)
document.forms[0].outputx.value=partA/2.54
partA= eval(document.forms[0].inputy.value)/(document.forms[0].scale.value)
document.forms[0].outputy.value=partA/2.54
partA= eval(document.forms[0].inputz.value)/(document.forms[0].scale.value)
document.forms[0].outputz.value=partA/2.54
}
}
frac()
}
function unit1()
{
document.forms[0].inunit.value="centimeters";
compute();
}
function unit2()
{
document.forms[0].inunit.value="inches";
compute();
}
function unit3()
{
document.forms[0].outunit.value="centimeters";
compute();
}
function unit4()
{
document.forms[0].outunit.value="inches";
compute();
}
// Called by Reset button - sets original values.
function resetIt()
{
document.forms[0].scale.value="6";
document.forms[0].input.value="10";
document.forms[0].output.value="";
document.forms[0].inunit.value="inches";
document.forms[0].outunit.value="inches";
}
-->
</SCRIPT>
[/CODE]
[code=html]
<FORM>
<div align="center"><TABLE id=table2 cellPadding=3 width=619
bgColor=#ffffff border=2>
<TBODY>
<TR>
<TD align=middle><FONT face=Verdana><font color="#FF0000"><STRONG>Scale</STRONG></font> <br>
</FONT><br/>
<FONT
face=Verdana color="#FF0000"><STRONG>Accuracy</STRONG></FONT></TD>
<TD align=middle colSpan=4>
<FONT face=Verdana><STRONG><font size="3"> 1:</font></STRONG></FONT><INPUT
size=4 value=12 name='scale'><br>
To Nearest <font size="3">=</font>
<INPUT
size=4 value="96 " name='accuracy' style="text-align: right"><sup>th </sup>
inch</TD>
<TD align=left width=263 rowSpan=3>
<CENTER><FONT face=Verdana><B>SCALE
DOWN</B></FONT></CENTER>
<UL>
<LI>To enter the scaling factor other than 1/12<sup>th</sup>,
highlight the default 12 and enter whatever scale you want; 24 for 1/24th scale; 144 for 1/144th scale; etc..
<LI>Next enter the level of accuracy you want.
To the nearest 24<sup>th</sup> inch, 48<sup>th</sup>
inch, etc.. (Read<b>
<a href="http://zooplies.com/Miniature_Haven/Custom_Tools/F_scale_converter.shtml#Caution:">
Caution</a></b>)<LI>In the boxes marked "<b><font color="#FF0000">input</font></b>",
enter the measurement of a real-world object in
either inches or centimeters (Read
<a href="http://zooplies.com/Miniature_Haven/Custom_Tools/F_scale_converter.shtml#frac">
<b>Fractions</b></a>)
<LI>Press <INPUT onclick=unit2() type=button value=in> button
for inches<br>
or <INPUT onclick=unit1() type=button value=cm>
button for centimeter
<LI>The scaled size of
that object is displayed in the boxes marked
"<b><font color="#FF0000">output</font></b>"
<LI>Your Answers will be displayed in both
decimal
and common fraction.</LI></UL></TD></TR>
<TR>
<TD align=middle><FONT
face=Verdana><STRONG><font color="#FF0000">Input</font>
in Inches, Centimeters or Millimeters only
</STRONG> </FONT></TD>
<TD align=middle>
x: <INPUT size=10 name=inputx><br>
y: <INPUT size=10 name=inputy><br>
z: <INPUT size=10 name=inputz></TD>
<TD align=middle><INPUT size=10 value=inches
name=inunit> </TD>
<TD align=middle><INPUT onclick=unit1() type=button value=cm>
</TD>
<TD align=middle><INPUT onclick=unit2() type=button value=in>
</TD></TR>
<TR>
<TD align=middle><FONT face=Verdana><STRONG><font color="#FF0000">Output</font>
in Decimal & Common Fractions</STRONG> </FONT></TD>
<TD align=middle>
x:
<INPUT size=10 name=outputx><br/>
<div id=answerx
style="border:solid black 1px; width: 112px;height: 40px"></div>
y:
<INPUT size=10 name=outputy><br/>
<div id=answery
style="border:solid black 1px; width: 112px;height: 40px"></div>
z:
<INPUT size=10 name=outputz><br/>
<div id=answerz
style="border:solid black 1px; width: 112px;height: 40px"></div>
</TD>
<TD align=middle><INPUT size=10 value=inches
name=outunit> </TD>
<TD align=middle><INPUT onclick=unit3() type=button value=cm>
</TD>
<TD align=middle><INPUT onclick=unit4() type=button value=in>
</TD></TR></TBODY></TABLE></div>
<BR><BR><B><a name="frac">Fractions:</a></B> When
entering numbers, make sure you're using only inches
and/or fractions, and enter them in a form the computer
will understands. i.e. If you input a mixed
measure like "<b>12-1/2</b>" the computer will evaluate
the expression as "<b>12</b> minus <b>1</b> divided by
<b>2</b>", the result of which is "<b>11.5</b>". You
must enter the expression the computer understands.
i.e. <B>"12+1/2"</B> (using a "<B>plus</B>" instead of the "minus") or as
<b>12.5</b>".
<SPAN
style="font-weight:700">The same would hold true for
centimeters and millimeters!</SPAN><br>
<br>
<b><font color="#FF0000">NEVER </font></b>input the
measure as "<b>12 1/2</b>" (without the "plus" or
"minus" operator) this will cause a JavaScript error!
<font color="#FF0000"><b><br>
<br>
NOTE!</b></font> This calculator doesn't understand Feet
or Meters - it requires them to be converted into
inches/centimeters. You can however enter
something like (5*12)+4+(3/4), which is like saying
"five feet four and three-quarter inches" (5 feet times
12 inches plus 4 inches plus 3/4 of an inch).
Computer understands that "*" = multiply,
"/" = divide, "+" = plus, "-" =
minus.<b><br>
<br>
<a name="Caution:">Caution:</a></b> Entering a
small level of accuracy can adversely affect your
results - the computer will always round to the nearest
scale factor. i.e. you enter a scale factor of 12,
and an accuracy of 12. This means that you are
only getting accuracy to the nearest inch for the scale
model, which means that if you need an item 3+1/2 inches
you'll get a scale result of 4/12 - which is really 4
inches. The decimal fraction displayed will be
correct and isn't affected by the accuracy level.</FORM></TD>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE>Scale Conversion Tool - Decimal to Fraction Tool</TITLE>
<SCRIPT>
<!--
function reduce(top,bot) {
var factorX //highest common factor
if ( top == 0 || bot == 0 ) {
factorX=1;
return "<sup>"+top+"</sup>/<sub>"+bot+"</sub>";
}
top = Math.abs( top );
bot = Math.abs( bot );
var factorX = 1;
//Find common factors of Numerator and Denominator
for ( var x = 2; x <= Math.min( top, bot ); x ++ ) {
var check1 = top / x;
if ( check1 == Math.round( check1 ) ) {
var check2 = bot / x;
if ( check2 == Math.round( check2 ) ) {
factorX = x;
}
}
}
top=top/factorX; //divide by highest common factor to reduce fraction
bot=bot/factorX; //divide by highest common factor to reduce fraction
return "<sup>"+top+"</sup>/<sub>"+bot+"</sub>";
}
function Calculate(value, acc)
{
if (value.match(/^d*.?d*$/)) {
var integer = parseInt(value.match(/^d*.?/)[0]);
var decimal = parseFloat("0"+value.match(/.d*$/)[0]);
var rationalise = Math.round(acc*decimal);
return integer+reduce(rationalise, acc);
} else {
return "Wrong Number Format Entered: Please Try Again";
}
}
function frac()
{
var valuex = document.forms[0].outputx.value
var valuey = document.forms[0].outputy.value
var valuez = document.forms[0].outputz.value
var acc = document.forms[0].accuracy.value
var answerx = document.getElementById("answerx");
var answery = document.getElementById("answery");
var answerz = document.getElementById("answerz");
if (acc == "")
{
alert("No Accuracy Entered: Please Try Again")
}
else
{
answerx.innerHTML = Calculate(valuex,acc)
answery.innerHTML = Calculate(valuey,acc)
answerz.innerHTML = Calculate(valuez,acc)
}
}
function compute()
{
if (document.forms[0].inunit.value==document.forms[0].outunit.value)
{
var partA = eval(document.forms[0].inputx.value)/(document.forms[0].scale.value);
document.forms[0].outputx.value=partA;
partA = eval(document.forms[0].inputy.value)/(document.forms[0].scale.value);
document.forms[0].outputy.value=partA;
partA = eval(document.forms[0].inputz.value)/(document.forms[0].scale.value);
document.forms[0].outputz.value=partA;
}
else
{
if (document.forms[0].inunit.value=="inches")
{
var partA= eval(document.forms[0].inputx.value)/(document.forms[0].scale.value)
document.forms[0].outputx.value=partA*2.54
partA= eval(document.forms[0].inputy.value)/(document.forms[0].scale.value)
document.forms[0].outputy.value=partA*2.54
partA= eval(document.forms[0].inputz.value)/(document.forms[0].scale.value)
document.forms[0].outputz.value=partA*2.54
}
else
{
var partA= eval(document.forms[0].inputx.value)/(document.forms[0].scale.value
)
document.forms[0].outputx.value=partA/2.54
partA= eval(document.forms[0].inputy.value)/(document.forms[0].scale.value)
document.forms[0].outputy.value=partA/2.54
partA= eval(document.forms[0].inputz.value)/(document.forms[0].scale.value)
document.forms[0].outputz.value=partA/2.54
}
}
frac()
}
function unit1()
{
document.forms[0].inunit.value="centimeters";
compute();
}
function unit2()
{
document.forms[0].inunit.value="inches";
compute();
}
function unit3()
{
document.forms[0].outunit.value="centimeters";
compute();
}
function unit4()
{
document.forms[0].outunit.value="inches";
compute();
}
// Called by Reset button - sets original values.
function resetIt()
{
document.forms[0].scale.value="6";
document.forms[0].input.value="10";
document.forms[0].output.value="";
document.forms[0].inunit.value="inches";
document.forms[0].outunit.value="inches";
}
-->
</SCRIPT>
[/code]
0.1.9 — BETA 6.17