[英]how to round figure value using php $_post
這顯示出這樣的結果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
?>
嘗試這個,
<?php
echo number_format((round(70.479, 1)),3);
?>
這就是你想要的結果
請嘗試使用PHP Round函數。
<?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
?>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.