少数点以下を繰り上げ、繰り下げする
サンプルソース
<input type="text" id="txt1" value="10.25"> <input type="text" id="txt2"> <input type="button" value="少数点以下を繰り上げる" onclick="document.all.txt2.value = Math.ceil(document.all.txt1.value)"> <input type="button" value="少数点以下を繰り下げる" onclick="document.all.txt2.value = Math.floor(document.all.txt1.value)"> |
解説
Math.ceil()で小数点以下を繰り上げます。Math.floor()で小数点以下を繰り下げます。
実行結果
関連する内容