0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

codecamp第3章‐7 課題(中級)

Last updated at Posted at 2023-12-05

変数$valueに代入されている値を「切り捨て」「切り上げ」「四捨五入」「小数点以下第三位四捨五入」した値を計算し表示するよう、以下のプログラムへ追記してください。

<?php
// $valueの値を定義
$value = 55.5555;

// 小数切り捨て値の処理を記述
$floor = floor($value);

// 小数切り上げの処理を記述
$ceil = ceil($value);

// 小数四捨五入の処理を記述
$round = round($value);

// 小数点以下第三位四捨五入の処理を記述
$round2 = round($value, 2);

?>

<!DOCTYPE html>
<html lang="ja">

<head>
    <meta charset="UTF-8">
    <title>課題</title>
</head>

<body>
    <p>元の値:<?php print $value; ?> </p>
    <p>小数切り捨て:<?php print $floor; ?></p>
    <p>小数切り上げ:<?php print $ceil; ?> </p>
    <p>小数四捨五入:<?php print $round; ?> </p>
    <p>小数点第三位で四捨五入:<?php print $round2; ?> </p>
</body>

</html>

結果

元の値:55.5555

小数切り捨て:55

小数切り上げ:56

小数四捨五入:56

小数点第三位で四捨五入:55.56

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?