小数点以下四捨五入・切り捨て・切り上げ(Math.round, Math.floor, Math.ceil)
<html>
<head>
<title>小数点以下四捨五入・切り捨て・切り上げ</title>
<script language="JavaScript">
<!--
function change(flag) {
switch(flag) {
case 1: document.form1.text2.value = Math.ceil(document.form1.text1.value);
break;
case 2: document.form1.text2.value = Math.floor(document.form1.text1.value);
break;
case 3: document.form1.text2.value = Math.round(document.form1.text1.value);
break;
}
}
//-->
</script>
</head>
<body>
<form action="" method="" name="form1">
小数点以下四捨五入・切り捨て・切り上げ<br>
<input type="text" name="text1" size="50"><br>
<br>
<input type="button" value="切り上げ" onClick="change(1)">
<input type="button" value="切り捨て" onClick="change(2)">
<input type="button" value="四捨五入" onClick="change(3)">
<br>
<br>
<input type="text" name="text2" size="50">
</form>
</body>
</html>
〔 実行する 〕