견적프로그램을 짯는데 결과값이 소수점 빈칸끝까지 내리가네요.ㅠ.ㅠ

매출이 오르면 내리는 수수료! 지금 수수료센터에서 전자결제(PG)수수료 비교견적 신청해 보세요!
견적프로그램을 짯는데 결과값이 소수점 빈칸끝까지 내리가네요.ㅠ.ㅠ

QA

견적프로그램을 짯는데 결과값이 소수점 빈칸끝까지 내리가네요.ㅠ.ㅠ

본문

<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>
이소스를 실행하시면
렌탈료가 소수점 빈칸 끝까지 주르르 내려가네요. 딱잘라 십원까지만 버림 하고 싶은데.. 도저히 엄두가 나질않네요.
하하하^^;; 어디서 뭘 적어야 할지...^^;;;

이 질문에 댓글 쓰기 :

답변 2


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;
}
 
total_sum =  Math.floor(total_sum/10) * 10 ; // 십자리 밑으로 버림
답변을 작성하시기 전에 로그인 해주세요.
전체 124,607 | RSS
QA 내용 검색

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1404호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT