如何使用php $ _post舍入图形值

时间:2013-11-13 04:52:40

标签: php

这显示了这样的结果 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
    ?>

2 个答案:

答案 0 :(得分:4)

试试这个,

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

这就是你想要的结果

答案 1 :(得分: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
?>