四捨五入する
サンプルソース
<input type="text" id="txt1" value="10.75"> <input type="text" id="txt2"> <input type="button" value="四捨五入する" onclick="document.all.txt2.value = Math.round(document.all.txt1.value)"> |
解説
Math.round()で小数点以下を四捨五入します。実行結果
関連する内容
<input type="text" id="txt1" value="10.75"> <input type="text" id="txt2"> <input type="button" value="四捨五入する" onclick="document.all.txt2.value = Math.round(document.all.txt1.value)"> |