JS(Vanilla)
숫자
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script type="text/javascript">
a1 = parseFloat(prompt("1")) ;
a2 = parseFloat(prompt("2"));
document.write(+(a1+a2).toFixed(12)+"<br>");
document.write(+(a1/a2).toFixed(12)+"<br>");
if (isNaN(a1)==false){
if(Number.isInteger(a1)==true){
document.write("정수"+"<br>");
}
else{
document.write("실수"+"<br>");
}
}
else if (isNaN(a1)==true){
document.write("NAN")
}
if (isNaN(a2)==false){
if(Number.isInteger(a2)==true){
document.write("정수"+"<br>")
}
else{
document.write("실수"+"<br>")
}
}
else if (isNaN(a2)==true){
document.write("NAN"+"<br>")
}
</script>
</body>
</html>
a1 = parseFloat(prompt("1")) ;
a2 = parseFloat(prompt("2"));
document.write(+(a1+a2).toFixed(12)+"<br>");
document.write(+(a1/a2).toFixed(12)+"<br>");
if (isNaN(a1)==false){
if(Number.isInteger(a1)==true){
document.write("정수"+"<br>");
}
else{
document.write("실수"+"<br>");
}
}
else if (isNaN(a1)==true){
document.write("NAN")
}
if (isNaN(a2)==false){
if(Number.isInteger(a2)==true){
document.write("정수"+"<br>")
}
else{
document.write("실수"+"<br>")
}
}
else if (isNaN(a2)==true){
document.write("NAN"+"<br>")
}
이외 기타 기초 문법들은 JavaScript 기초 를 참고한다.
document.write(+(a1+a2).toFixed(12)+"<br>");
+를 값 앞에 붙이면 해당 값을 숫자로 변환하도록 한다.