견적프로그램을 짯는데 결과값이 소수점 빈칸끝까지 내리가네요.ㅠ.ㅠ 채택완료
<table width="640" height="480" cellspacing="0" cellpadding="0">
<tr>
<td align="center"><table BORDER=0 CELLPADDING=0 CELLSPACING=0 >
<form name="frm" id="frm" action="">
<tr>
<td align="right">
컴퓨터종류</td>
<td colspan="2"><select id="product" onchange="javascript:sum();">
<option >-------------------</option>
<option value=210000>컴퓨터A</option>
<option value=420000>컴퓨터B</option>
</select> </td>
</tr>
<tr>
<td align="right">
컴퓨터댓수</td>
<td colspan="2"><input type="text" id="num" rows="1" style="width:160px; height:20px;" OnKeyUp="javascript:sum();">
</textarea></td>
</tr>
<tr>
<td align="right">
렌탈기간</td>
<td colspan="2"><select id="rent_time" onchange="javascript:sum();">
<option >-------------------</option>
<option value=24>24개월</option>
<option value=36>36개월</option>
</select> </td>
</tr>
<tr>
<td align="right">대당렌탈료
</td>
<td width="50" align="right">
<input name="opt_sum" type="text" value="" size="12" style="width:147px;" align="right" />
</td>
<td align="right">원
</td>
</tr>
<tr>
<td align="right">총렌탈료
</td>
<td width="100" align="right">
<input name="total_sum" type="text" value="" size="12" style="width:147px;" align="right" />
</td>
<td align="right">원
</td>
</tr>
</form>
</table>
<script>
function sum() {
var frm = document.frm; //젤 먼저...
var product = frm.product.value; // 각 변수들에 입력된 값 넣어줌
var num = frm.num.value;
var rent_time = frm.rent_time.value;
var opt_sum;
var total_sum;
if(frm.rent_time.value==24) {
opt_sum = product * 1.17 / rent_time;
total_sum = product * 1.17 * num / rent_time;
}
else if(frm.rent_time.value==36) {
opt_sum = product * 1.26 / rent_time;
total_sum = product * 1.26 * num / rent_time;
}
frm.opt_sum.value = opt_sum; // 값 넣어줌.
frm.total_sum.value = total_sum;
}
</script>
</td>
</tr>
</table>
이소스를 실행하시면
렌탈료가 소수점 빈칸 끝까지 주르르 내려가네요. 딱잘라 십원까지만 버림 하고 싶은데.. 도저히 엄두가 나질않네요.
하하하^^;; 어디서 뭘 적어야 할지...^^;;;
<tr>
<td align="center"><table BORDER=0 CELLPADDING=0 CELLSPACING=0 >
<form name="frm" id="frm" action="">
<tr>
<td align="right">
컴퓨터종류</td>
<td colspan="2"><select id="product" onchange="javascript:sum();">
<option >-------------------</option>
<option value=210000>컴퓨터A</option>
<option value=420000>컴퓨터B</option>
</select> </td>
</tr>
<tr>
<td align="right">
컴퓨터댓수</td>
<td colspan="2"><input type="text" id="num" rows="1" style="width:160px; height:20px;" OnKeyUp="javascript:sum();">
</textarea></td>
</tr>
<tr>
<td align="right">
렌탈기간</td>
<td colspan="2"><select id="rent_time" onchange="javascript:sum();">
<option >-------------------</option>
<option value=24>24개월</option>
<option value=36>36개월</option>
</select> </td>
</tr>
<tr>
<td align="right">대당렌탈료
</td>
<td width="50" align="right">
<input name="opt_sum" type="text" value="" size="12" style="width:147px;" align="right" />
</td>
<td align="right">원
</td>
</tr>
<tr>
<td align="right">총렌탈료
</td>
<td width="100" align="right">
<input name="total_sum" type="text" value="" size="12" style="width:147px;" align="right" />
</td>
<td align="right">원
</td>
</tr>
</form>
</table>
<script>
function sum() {
var frm = document.frm; //젤 먼저...
var product = frm.product.value; // 각 변수들에 입력된 값 넣어줌
var num = frm.num.value;
var rent_time = frm.rent_time.value;
var opt_sum;
var total_sum;
if(frm.rent_time.value==24) {
opt_sum = product * 1.17 / rent_time;
total_sum = product * 1.17 * num / rent_time;
}
else if(frm.rent_time.value==36) {
opt_sum = product * 1.26 / rent_time;
total_sum = product * 1.26 * num / rent_time;
}
frm.opt_sum.value = opt_sum; // 값 넣어줌.
frm.total_sum.value = total_sum;
}
</script>
</td>
</tr>
</table>
이소스를 실행하시면
렌탈료가 소수점 빈칸 끝까지 주르르 내려가네요. 딱잘라 십원까지만 버림 하고 싶은데.. 도저히 엄두가 나질않네요.
하하하^^;; 어디서 뭘 적어야 할지...^^;;;
답변 2개
채택된 답변
+20 포인트
11년 전
Copy
function sum() {
var f = document.forms.frm.elements,
product = f.product.value,
num = f.num.value,
rent_time = f.rent_time.value,
ratios = {24:1.17, 36:1.26};
f.opt_sum.value = floor(product * ratios[rent_time] / rent_time);
f.total_sum.value = floor(product * ratios[rent_time] * num / rent_time);
}
function floor(num) {
return Math.floor(num / 10) * 10;
}
로그인 후 평가할 수 있습니다
답변에 대한 댓글 1개
11년 전
음..어렵네요.ㅜ..ㅜ 간단한건줄 알았는데.. 예상외로 복잡하네여^^:; 하하 역시 배움의 길은 가깝고도 멀다고 했던가요?.?아무튼 감사합니다^^*
댓글을 작성하려면 로그인이 필요합니다.
겸손1935
11년 전
total_sum = Math.floor(total_sum/10) * 10 ; // 십자리 밑으로 버림
로그인 후 평가할 수 있습니다
답변에 대한 댓글 1개
11년 전
아아~!! 자세히 보니까 겸손님 말대로 했다가 문제를 해결했네여^^'' 겸손님 감사합니다.
답변채택 도로 주워담을수 없죠?.? ㅎㅎㅎㅎㅎ
답변채택 도로 주워담을수 없죠?.? ㅎㅎㅎㅎㅎ
댓글을 작성하려면 로그인이 필요합니다.
답변을 작성하려면 로그인이 필요합니다.
로그인