我已经能够将两个变量从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
您可以尝试使用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>";
}