2008年05月30日

数値を切り捨てる

数値を切り捨てる
入力された数値を切り捨てます。
切り捨てにはfloor()を使います。

[ 数値を切り捨てる JavaScript ]

// 数値を切り捨てる
function myCalc(form){
form.myResult2.value = Math.floor(parseFloat(form.myData.value));
}

[ 数値を切り捨てる XHTML ]

<?xml version="1.0" encoding="Shift_JIS"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja" lang="ja">
<head>
<title>タイトル</title>
<meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS" />
<meta name="description" content="サイト内容" />
<meta name="keywords" content="サイトキーワード" />
<meta name="author" content="css+xhtml+seo" />
<meta name="copyright" content="Copyright &copy; css+xhtml+seo. All Rights Reserved." />
<link rel="index" href="./index.html" />
<link rel="next" href="next.html" />
<link rel="prev" href="prev.html" />
<link rev="made" href="mailto:●●●@●●●" title="send mail" />
<link rel="stylesheet" href="css/●●●.css" type="text/css" />
<script src="js/javascript.js" type="text/javascript"></script>
<meta http-equiv="content-script-type" content="" />
<meta http-equiv="content-style-type" content="text/javascript" />
</head>
<body>

<form action="">
<input type="text" name="myData" value="" /><br />
<input type="button" value="計算" onclick="myCalc(this.form)" /><br />
切り捨て<input type="text" name="myResult2" value="" /><br />
</form>

</body>
</html>

posted by javascript at 16:55| 数値を切り捨てる | このブログの読者になる | 更新情報をチェックする