1

这是显示这样的结果 70.479

我想要这样的结果 70.500

我该怎么做请帮我解决这个问题谢谢

<?php //Starting of php 
    if(isset($_POST['submit']))//if the submit button has pressed
    {
    $first = $_POST['first']; //Getting Value of first integer from add.html
    $sec = $_POST['sec']; //Getting Value of Second integer from add.html
    $res = $first * $sec *75 /365 /30; //Adding the two values and placing the added result to 'res' variable
    echo 'Added Result:';
    echo "<br>Rounded value of the number = ".round($res,3); 

    }
    //Ending of php
    ?>
4

2 回答 2

5

试试这个,

<?php 
   echo number_format((round(70.479, 1)),3);
?>

这就是你想要的结果

于 2013-11-13T05:04:18.153 回答
0

请尝试使用 PHP 轮函数。

<?php
echo number_format(round(70.479, 1), 3); // 70.500
?>

http://php.net/manual/en/function.round.php

<?php
echo round(3.4);         // 3
echo round(3.5);         // 4
echo round(3.6);         // 4
echo round(3.6, 0);      // 4
echo round(1.95583, 2);  // 1.96
echo round(1241757, -3); // 1242000
echo round(5.045, 2);    // 5.05
echo round(5.055, 2);    // 5.06
?>
于 2013-11-13T04:57:25.117 回答