Thema: Formular für den Einsatz von Zahlen ab_ und aufrunden


Eine Zahl ab- und/oder aufrunden

Das Beispiel soll eine Zahl ab- oder aufrunden. Es soll möglichst in einem kurzen Code geschrieben werden und der Dateiname soll c66.php heißen. Wenn man eine Zahl in das Textfeld eingibt und auf die Schaltfläche Send klickt, muss das Ergebnis unter dem Formular erscheinen!



<form class="mb-2" action = "c66.php" method = "post">
	<div class="form-group">
    <label class='control-label' for='inputZahl'>Eine Zahl eingeben: </label>
    <input type="text" name="zahl"  id='inputZahl' placeholder="Enter eine Zahl" />
    </div>
    <div class="form-group">
         <button type='submit' name="send" class='btn btn-primary'>
		<span class='fa fa-send'></span> Send</button>
	 </div>
</form>
<?php
	if(isset($_POST["send"])) { 
		$zahl = $_POST["zahl"];
		echo "<p align='center'>Umwandeln von $zahl  Ganzzahlen:<br />";
		echo "<table class='table striped'>";
		echo "<thead>";
		echo "<thead>";
		echo "<tr>";
		echo "<th>Zahl</th>";
      echo "<th>Nächstniedrigere Ganzzahl</th>";
		echo "<th>nächsthöhere Ganzzahl</th>";
		echo "<th>kaufmännisch gerundet</th>";
		echo "</tr>";
		echo "</thead>";
		echo "<tbody>";
		echo "<tr>";
      echo "<td>" . $zahl . "</td>";
      echo "<td>" . floor($zahl) . "</td>";
      echo "<td>" . ceil($zahl) . "</td>";
      echo "<td>" . round($zahl) . "</td>";
      echo "</tr>";
		echo "</tbody>";
		echo "</table>";
	}	
?>