사이트 내 전체검색
단위변환
로빈아빠
https://cmd.kr/javascript/682 URL이 복사되었습니다.

본문

단위변환

<HTML>
<HEAD>
<META http-equiv=Content-Type content="text/html; charset=euc-kr">
<SCRIPT>
function convertform(form){
	var firstvalue = 0;
	for (var i = 1; i <= form.count; i++) {
		// Find first non-blank entry
		if (form.elements[i].value != null && form.elements[i].value.length != 0) {
			// Verify that value is a number
			for (var j = 0; j < form.elements[i].value.length; j++) {
				var ch = form.elements[i].value.substring(j, j + 1)
				if ((ch < "0" || "9" < ch) && ch != '.') {
					alert(" 데이터 입력이 잘못되었음: " + form.elements[i].value);
					clearform(form);
					return false;
				}
			}
			if (i == 1 && form.elements[2].value != "") return false;
			firstvalue = form.elements[i].value / form.elements[i].factor;
			break;
		}
	}
	if (firstvalue == 0) {
		clearform(form);
		return false;
	}
	for (var i = 1; i <= form.count; i++) {
		form.elements[i].value = firstvalue * form.elements[i].factor;
		form.elements[i].value = formatvalue(form.elements[i].value, form.rsize);
	}
	return true;
}

function formatvalue(input, rsize) {
	var invalid = "**************************";
	var nines = "999999999999999999999999";
	if (input.length <= rsize) return input;
	if (strpos(input, 'e') != -1 || eval(input) > eval(nines.substring(0,rsize)+".4"))
		return invalid.substring(0, rsize);
	var rounded = "" + (eval(input) + (eval(input) - eval(input.substring(0, rsize))));
	return rounded.substring(0, rsize);
}

function strpos(str, ch) {
	for (var i = 0; i < str.length; i++)
		if (str.substring(i, i+1) == ch) return i;
	return -1;
}

function resetform(form) {
	clearform(form);
	form[1].value = 1;
	convertform(form);
	return true;
}

function clearform(form) {
	for (var i = 1; i <= form.count; i++) form[i].value = "";
	return true;
}
</SCRIPT>
<BODY vLink=#550055 link=black bgColor=#ffffff background="" scroll=no>
<BR><BR><FONT color=#663311 size=4><B>단위변환계산기</B></FONT> 
<FORM>
<TABLE cellSpacing=0 bgColor=#d1e6cc border=1>
	<TBODY>
	<TR>
		<TD align=middle><SMALL>미터</SMALL></TD>
		<TD align=middle><SMALL>인치</SMALL></TD>
		<TD align=middle><SMALL>피트</SMALL></TD>
		<TD align=middle><SMALL>야드</SMALL></TD>
		<TD align=middle><SMALL>마일</SMALL></TD>
		<TD align=middle><SMALL>자</SMALL></TD>
		<TD><SMALL><INPUT onclick=clearform(this.form) type=button value=Clear></SMALL></TD>
	</TR>
	<TR>
		<TD><INPUT size=6 name=val1></TD>
		<TD><INPUT size=6 name=val2></TD>
		<TD><INPUT size=6 name=val3></TD>
		<TD><INPUT size=6 name=val4></TD>
		<TD><INPUT size=6 name=val5></TD>
		<TD><INPUT size=6 name=val6></TD>
		<TD><SMALL><INPUT onclick=convertform(this.form) type=button value=변환></SMALL></TD>
	</TR>
	</TBODY>
</TABLE>
</FORM>

<FORM>
<TABLE cellSpacing=0 bgColor=#d1e6cc border=1>
	<TBODY>
	<TR>
		<TD align=middle><FONT size=2>킬로그램</FONT></TD>
		<TD align=middle><SMALL>온스</SMALL></TD>
		<TD align=middle><SMALL>파운드</SMALL></TD>
		<TD align=middle><SMALL>근</SMALL></TD>
		<TD align=middle><SMALL>관</SMALL></TD>
		<TD align=middle><SMALL>돈</SMALL></TD>
		<TD><SMALL><INPUT onclick=clearform(this.form) type=button value=Clear></SMALL></TD>
	</TR>
	<TR>
		<TD><INPUT size=6 name=val1></TD>
		<TD><INPUT size=6 name=val2></TD>
		<TD><INPUT size=6 name=val3></TD>
		<TD><INPUT size=6 name=val4></TD>
		<TD><INPUT size=6 name=val5></TD>
		<TD><INPUT size=6 name=val6></TD>
		<TD><SMALL><INPUT onclick=convertform(this.form) type=button value=변환></SMALL></TD>
	</TR>
	</TBODY>
</TABLE>
</FORM>

<FORM>
<TABLE cellSpacing=0 bgColor=#d1e6cc border=1>
	<TBODY>
	<TR>
		<TD align=middle><SMALL>m<SUP>3</SUP></SMALL></TD>
		<TD align=middle><SMALL>리터</SMALL></TD>
		<TD align=middle><SMALL>갤런</SMALL></TD>
		<TD align=middle><SMALL>홉</SMALL></TD>
		<TD align=middle><SMALL>되</SMALL></TD>
		<TD align=middle><SMALL>말</SMALL></TD>
		<TD><SMALL><INPUT onclick=clearform(this.form) type=button value=Clear></SMALL></TD>
	</TR>
	<TR>
		<TD><INPUT size=6 name=val1></TD>
		<TD><INPUT size=6 name=val2></TD>
		<TD><INPUT size=6 name=val3></TD>
		<TD><INPUT size=6 name=val4></TD>
		<TD><INPUT size=6 name=val5></TD>
		<TD><INPUT size=6 name=val6></TD>
		<TD><SMALL><INPUT onclick=convertform(this.form) type=button value=변환></SMALL></TD>
	</TR>
	</TBODY>
</TABLE>
</FORM>

<FORM>
<TABLE cellSpacing=0 bgColor=#d1e6cc border=1>
	<TBODY>
	<TR>
		<TD align=middle><SMALL>m<SUP>2</SUP></SMALL></TD>
		<TD align=middle><SMALL>평</SMALL></TD>
		<TD align=middle><SMALL>에이커</SMALL></TD>
		<TD align=middle><SMALL>ft<SUP>2</SUP></SMALL></TD>
		<TD align=middle><SMALL>yd<SUP>2</SUP></SMALL></TD>
		<TD align=middle width=55><SMALL>&nbsp;</SMALL></TD>
		<TD><SMALL><INPUT onclick=clearform(this.form) type=button value=Clear></SMALL></TD>
	</TR>
	<TR>
		<TD><INPUT size=6 name=val1></TD>
		<TD><INPUT size=6 name=val2></TD>
		<TD><INPUT size=6 name=val3></TD>
		<TD><INPUT size=6 name=val4></TD>
		<TD><INPUT size=6 name=val5></TD>
		<TD>&nbsp;</TD>
		<TD><SMALL><INPUT onclick=convertform(this.form) type=button value=변환></SMALL></TD>
	</TR>
	</TBODY>
</TABLE>
</FORM>

<SCRIPT>
document.forms[0].count = 6;  // number of unit types
document.forms[0].rsize = 7;  // Rounding size, use same as SIZE
document.forms[0].val1.factor = 1;   //m
document.forms[0].val2.factor = 39.37007874;  //in.
document.forms[0].val3.factor = 3.280839895;  //ft.
document.forms[0].val4.factor = 1.093613298;  // m to yards.
document.forms[0].val5.factor = 0.00062137119; //mi.
document.forms[0].val6.factor = 3.3; //nm.

document.forms[1].count = 7;
document.forms[1].rsize = 6;
document.forms[1].val1.factor = 1.000;
document.forms[1].val2.factor = 35.273944; //oz.
document.forms[1].val3.factor = 2.2046215; //lb.
document.forms[1].val4.factor = 1.6666; //근
document.forms[1].val5.factor = 0.26666;  //관
document.forms[1].val6.factor = 266.6666; // 돈

document.forms[2].count = 6;
document.forms[2].rsize = 6;
document.forms[2].val1.factor = 1.000;   // m3
document.forms[2].val2.factor = 1000;  //리터
document.forms[2].val3.factor = 264.186; //갤론
document.forms[2].val4.factor = 5543.52; // 홉
document.forms[2].val5.factor = 554.325; //되
document.forms[2].val6.factor = 55.4325; //말

document.forms[3].count = 5;
document.forms[3].rsize = 6;
document.forms[3].val1.factor = 1.000;  //m2
document.forms[3].val2.factor = 0.3025;  //평
document.forms[3].val3.factor = 0.00024; //에이커 
document.forms[3].val4.factor = 10.764; //ft2
document.forms[3].val5.factor = 1.1958; //yd2
</SCRIPT>

댓글목록

등록된 댓글이 없습니다.

831 (3/17P)

Search

Copyright © Cmd 명령어 3.142.131.51