■文字列やn進数を整数、浮動小数点数に変換したい

入力文字列:

変換結果:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Script-Type" content="text/javascript">
<meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS">
<meta http-equiv="Content-Style-Type" content="text/css">
<title>文字列やn進数を整数、浮動小数点数に変換したい</title>
<script type="text/JavaScript">
<!--
function calc1(n) {
str = document.fm1.i_data.value;
ans = parseInt(str,n);
document.fm1.o_data.value = ans;
}
function calc2() {
str = document.fm1.i_data.value;
ans = parseFloat(str);
document.fm1.o_data.value = ans;
}
// -->
</script>
</head>
<body>
<p>■文字列やn進数を整数、浮動小数点数に変換したい</p>
<form name="fm1">
<p>入力文字列:<input type="text" name="i_data" size="50"></p>
<p><input type="button" value="2進数の変換" onclick="calc1(2)">
<input type="button" value="16進数の変換" onclick="calc1(16)">
<input type="button" value="整数変換" onclick="calc1()">
<input type="button" value="浮動小数点数変換" onclick="calc2()"></p>
<p>変換結果:<input type="text" name="o_data" size="50"></p>
</form>

</body>
</html>


★解説★