doufu6423 2016-01-31 18:15
浏览 18
已采纳

尝试将PHP公式插入表中

The table I am trying to make should:

The first table should include the results of using PHP to calculate the area and circumference of a circle

Additionally, I am trying to make the answers rounded to the first 2 decimals in the floating point number. Any help would be appreciated.

<!DOCTYPE html>
<!--
    Author:Randy Gilman
-->

<?php
$cir_area = M_PI * sqrt(2.65)
$cir_circum = 2 * M_PI * 2.65
?>
<html>
    <head>
        <meta charset="UTF-8">
        <title> Randy's Table</title>
    </head>
    <body>
    <table border = "5px">
    <tr>
        <th> Shape </th>
        <th> Parameter and Values </th>
        <th> Area </th>
        <th> Perimeter </th>
    </tr>
    <tr>
        <th> Circle </th>
        <th> radius = 2.65 meters  </th>
        <th> <?php echo "$cir_area"?> </th>
        <th> <?php echo "$cir_circum"?> </th>
    </tr>   
       </table>
        </body>
</html>
  • 写回答

4条回答 默认 最新

  • dongtui2029 2016-01-31 18:19
    关注

    PHP uses semicolons to end a line:

    echo "Hello";

    If you try to run your code, you'll get this error:

    Message : syntax error, unexpected '$cir_circum' (T_VARIABLE)

    This means, you forgot to end the lines with a semicolon.

    Your PHP should look like this:

    <?php
    $cir_area = M_PI * sqrt(2.65);
    $cir_circum = 2 * M_PI * 2.65;
    ?>
    

    To round numbers, you could use number_format:

    <?php
    $cir_area = number_format(M_PI * sqrt(2.65), 2);
    $cir_circum = number_format(2 * M_PI * 2.65, 2);
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 Llama如何调用shell或者Python
  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?
  • ¥15 win10权限管理,限制普通用户使用删除功能
  • ¥15 minnio内存占用过大,内存没被回收(Windows环境)
  • ¥65 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi