Newer
Older
Teatime / book-js / answer / 4-03_math / step1 / index.html
@KAOKA Daisuke KAOKA Daisuke on 29 Jan 2022 1 KB add file
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>4-03_math</title>
<link href="../../_common/images/favicon.ico" rel="shortcut icon">
<link href="https://fonts.googleapis.com/css?family=M+PLUS+1p:400,500" rel="stylesheet">
<link href="../../_common/css/style.css" rel="stylesheet">
<style>
span {
    font-weight: bold;
    color: #ed8a29;
}
</style>
</head>
<body>
<header>
<div class="container">
<h1>小数第◯位で切り捨てる</h1>
<h2>四則演算以外の計算をする</h2>
</div><!-- /.container -->
</header>
<main>
<div class="container">
<section>
    <p>円周率は <span id="pi"></span> です。</p>
    <p>ふつうに切り捨てると <span id="floor"></span> です。</p>
    <p>小数第2位で切り捨てると <span id="output"></span> です。</p>
</section>
</div><!-- /.container -->
</main>
<footer>
<div class="container">
<p>JavaScript Samples</p>
</div><!-- /.container -->
</footer>
<script>
'use strict';

document.getElementById('pi').textContent = Math.PI;
document.getElementById('floor').textContent = Math.floor(Math.PI);

function point(num, digit) {
    const mover = 10 ** digit;
    return Math.floor(num * mover) / mover;
}

document.getElementById('output').textContent = point(Math.PI, 2);
</script>
</body>
</html>