Beispiel:JS-toExponential.html

Aus SELFHTML-Wiki
Wechseln zu: Navigation, Suche
<!DOCTYPE html>
<html lang="de">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" href="./Beispiel:SELFHTML-Beispiel-Grundlayout.css">

<script>
document.addEventListener('DOMContentLoaded', function () {
	const werteTabelle = document.querySelector('#werteTabelle tbody');
    const Wert = 13.000012345;
    for (let exponent = 1; exponent <= 7; exponent++) {
        // Neue Zeile am Tabellenende
		const werteZeile = werteTabelle.insertRow();
        // Spalten mit Beschriftung und Wert erzeugen
        werteZeile.insertCell().textContent = 'toExponential('+ exponent + ')';
        werteZeile.insertCell().textContent = Wert.toExponential(exponent);
	}
});
	
</script>
<style>
#werteTabelle {
  border-collapse: collapse;
}
th, td {
  border: 1px solid black;
  padding: 0.2em;
}
th {
  background-color: grey;
  color: white;
  padding: 0.5em 1em;
}
td {
  text-align: right;
  padding: .5em;
}
</style>
  <title>toExponential()</title>
</head>
<body>
  <h1>toExponential()</h1>
 
<main>
    <table id="werteTabelle">
    <thead>
        <tr><th>Genauigkeit</th><th>Wert</th></tr>
    </thead>
    <tbody>
    </tbody>
    </table>
    

</main>

</body>
</html>