简体   繁体   English

如何使用PHP $ _post舍入数值

[英]how to round figure value using php $_post

this is showing result like this 70.479 这显示出这样的结果70.479

and i want result like that 70.500 我想要这样的结果70.500

how can i do this please help me to fix this issue thanks 我该怎么办,请帮助我解决此问题,谢谢

<?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
    ?>

Try this, 尝试这个,

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

this is what you want in result 这就是你想要的结果

Please try with PHP round function. 请尝试使用PHP Round函数。

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

http://php.net/manual/en/function.round.php 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
?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM