我已经能够从mysqli查询中除以两个变量...如何将数字除以两个小数位/ toFIxed(2)
php
$Date = $_GET['date'];
$Win = 'Win';
$testsql="
SELECT
count(*) AS bet_count,
SUM(IF(result ='$Win', 1, 0)) AS win_count
FROM bets WHERE betDate = '$Date' GROUP BY betDate
";
$testresult = mysqli_query($connection, $testsql);
while ($testrow = mysqli_fetch_assoc($testresult))
{
echo "<tr>";
echo "<td class='text-center'>".($testrow['bet_count']/$testrow['win_count']). "</td>";
echo "</tr>";
}
因此,bet_count / win_count可以正常工作.....我只需要整数例如2.371237234保留两位小数2.37
答案 0 :(得分:4)
您可以尝试使用number_format()函数:
<?php
$Date = $_GET['date'];
$Win = 'Win';
$testsql = "
SELECT
count(*) AS bet_count,
SUM(IF(result ='$Win', 1, 0)) AS win_count
FROM bets WHERE betDate = '$Date' GROUP BY betDate
";
$testresult = mysqli_query($connection, $testsql);
while ($testrow = mysqli_fetch_assoc($testresult)) {
echo "<tr>";
$value = number_format($testrow['bet_count']/$testrow['win_count'], 2, '.', '');
echo "<td class='text-center'>".$value."</td>";
echo "</tr>";
}