Web Developer's Room
HOME > JavaScript サンプル集 > 数字     

数字

2つの数字の大きい数字・小さい数字を表示する

<html>
<body>

<input type="text" id="txt1" value="15">
<input type="text" id="txt2" value="45">
<input type="button" value="大きい数字を表示する" onclick="alert(Math.max(document.all.txt1.value,document.all.txt2.value))">
<input type="button" value="小さい数字を表示する" onclick="alert(Math.min(document.all.txt1.value,document.all.txt2.value))">

</body>
</html>

【解説】
Math.max(a,b)でa,bの大きい方を返す。
Math.min(a,b)でa,bの小さい方を返す。
 サンプル


関連リンク
  • 乱数を生成する
  • 少数点以下を繰り上げ、繰り下げする
  • 四捨五入する
  • 絶対値を返す



  • スポンサードリンク


    (C) Web Developer's Room All rights reserved.