我已经能够从 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>";
}
关于php mysqli 获取数据并将两个变量除以Fixed(2)/两位小数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55182139/