소수점 계산 관련하여 정보
소수점 계산 관련하여본문
function merong() {
wr_5 = document.getElementById('wr_5');
wr_6 = document.getElementById('wr_6');
wr_28 = document.getElementById('wr_28');
wr_28.value = parseInt(wr_5.value) * parseInt(wr_6.value) * 2500;니다.
}
----------------------------------------------
자바 스크립트를 위와 같이 입력을 하고
------------------------------------------------
<B>가로</B>
<input type=text name=wr_5 id=wr_5 onchange="merong()" value="<?=$write[wr_5]?>" size="5" style="font-style:normal; font-weight:bold; font-size:10; color:rgb(255,153,0); text-decoration:blink; border-width:3px; border-style:solid;" maxlength="5" id="wr_5" itemname="556" />m X <b>세로</b>
<input type=text name="wr_6" id=wr_6 onchange="merong()" size="5" maxlength="5" itemname="555" value="<?=$write[wr_6]?>" style="font-style:normal; font-weight:bold; font-size:10; color:rgb(255,153,0); text-decoration:blink; border-width:3px; border-style:solid;" />m =
<input type=text name=wr_28 id=wr_28 size="15" onchange="merong3()" maxlength="5" itemname="557" value="<?=$write[wr_28]?>" style="font-style:normal; font-weight:bold; font-size:15; color:rgb(255,153,0); text-decoration:blink; border-width:3px; border-style:solid;" />원<br>
---------------------------------------------------------------------------------
이렇게 해서 입력을 받았는데요.
그런데...... 소수점 계산이 안되네요.
보여질때는 가로 "00" m * 세로 "00"m = "00"원
이렇게 출력이 되는 건데요.
가로 세로의 "00"을 입력시 소수점을 입력하면 정수만 즉 3.5 * 5.4를 계산하면
3*5*2500=37500 원이 나옵니다.
2500은 단가고요.
길이다 보니 소수점은 2자리수까지 가야 합니다. 어떻게 하면 계산을 할 수 있을 까요?
wr_5 = document.getElementById('wr_5');
wr_6 = document.getElementById('wr_6');
wr_28 = document.getElementById('wr_28');
wr_28.value = parseInt(wr_5.value) * parseInt(wr_6.value) * 2500;니다.
}
----------------------------------------------
자바 스크립트를 위와 같이 입력을 하고
------------------------------------------------
<B>가로</B>
<input type=text name=wr_5 id=wr_5 onchange="merong()" value="<?=$write[wr_5]?>" size="5" style="font-style:normal; font-weight:bold; font-size:10; color:rgb(255,153,0); text-decoration:blink; border-width:3px; border-style:solid;" maxlength="5" id="wr_5" itemname="556" />m X <b>세로</b>
<input type=text name="wr_6" id=wr_6 onchange="merong()" size="5" maxlength="5" itemname="555" value="<?=$write[wr_6]?>" style="font-style:normal; font-weight:bold; font-size:10; color:rgb(255,153,0); text-decoration:blink; border-width:3px; border-style:solid;" />m =
<input type=text name=wr_28 id=wr_28 size="15" onchange="merong3()" maxlength="5" itemname="557" value="<?=$write[wr_28]?>" style="font-style:normal; font-weight:bold; font-size:15; color:rgb(255,153,0); text-decoration:blink; border-width:3px; border-style:solid;" />원<br>
---------------------------------------------------------------------------------
이렇게 해서 입력을 받았는데요.
그런데...... 소수점 계산이 안되네요.
보여질때는 가로 "00" m * 세로 "00"m = "00"원
이렇게 출력이 되는 건데요.
가로 세로의 "00"을 입력시 소수점을 입력하면 정수만 즉 3.5 * 5.4를 계산하면
3*5*2500=37500 원이 나옵니다.
2500은 단가고요.
길이다 보니 소수점은 2자리수까지 가야 합니다. 어떻게 하면 계산을 할 수 있을 까요?
댓글 전체
wr_28.value = parseInt(wr_5.value) * parseInt(wr_6.value) * 2500;
parseInt 는 정수형으로 표현하라는 뜻입니다.
wr_28.value = wr_5.value * wr_6.value * 2500;
이렇게 수정하시면 될 듯합니다.
parseInt 는 정수형으로 표현하라는 뜻입니다.
wr_28.value = wr_5.value * wr_6.value * 2500;
이렇게 수정하시면 될 듯합니다.
http://www.w3schools.com/jsref/jsref_parseFloat.asp
parseFloat()를 써 보세요.
parseFloat()를 써 보세요.
아 그렇군요 답변감사합니다.