gpt4 book ai didi

php - MYSQL echo 显示十进制和非十进制

转载 作者:太空宇宙 更新时间:2023-11-03 10:33:36 25 4
gpt4 key购买 nike

我从 mysql 数据库中获取数据。 3 个 echo 中的 2 个显示数字后面的一个点。例如: 32500.00€第三个没有告诉我。刚刚:32500。在最好的情况下,我希望在回显中使用这种格式:32.500.00€

这是我的代码:

$sum_success_sql = "select SUM(kredithhe) as sum from wp_participants_database where angenommen = 'Ja' And standort = '" . $location['standort'] . "'";
$sum_success_res = runQuery($sum_success_sql, $pdo);

$sum_fail_sql = "select SUM(kredithhe) as sum from wp_participants_database where angenommen = 'Nein' And standort = '" . $location['standort'] . "'";
$sum_fail_res = runQuery($sum_fail_sql, $pdo);

$count_fail_sql = "select count(*) as num from wp_participants_database where angenommen = 'Nein' And standort = '" . $location['standort'] . "'";
$count_fail_res = runQuery($count_fail_sql, $pdo);

$count_success_sql = "select count(*) as num from wp_participants_database where angenommen = 'Ja' And standort = '" . $location['standort'] . "'";
$count_success_res = runQuery($count_success_sql, $pdo);

$temp = array();

$temp['location'] = $location['standort'];
$temp['sum_fail'] = $sum_fail_res['sum'];
$temp['sum_success'] = $sum_success_res['sum'];
$temp['num_fail'] = $count_fail_res['num'];
$temp['num_success'] = $count_success_res['num'];
$temp['num_total'] = $count_success_res['num'] + $count_fail_res['num'];
$temp['sum_total'] = $sum_fail_res['sum'] + $sum_success_res['sum'];

输出如下:

<td><?php echo utf8_encode($res['location']) ?></td>
<td><?php echo $res['num_total'] ?></td>
<td><?php echo $res['num_success'] ?></td>
<td><?php echo $res['num_fail'] ?></td>
<td><?php echo $res['sum_total'] ?>€</td>
<td><?php echo $res['sum_fail'] ?>€</td>
<td><?php echo $res['sum_success'] ?>€</td>

这是结果:

Location    NR  NR  NR 39500€   28000.00€   11500.00€

最佳答案

使用 number_format() 函数。

例子:

$number = 1000;
echo number_format($number, 2);

output: 1,000.00

关于php - MYSQL echo 显示十进制和非十进制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53170020/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com