mysql echo显示十进制和非十进制

4jb9z9bj  于 2021-06-18  发布在  Mysql
关注(0)|答案(2)|浏览(457)

我从mysql数据库获取数据。3个回声中的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€
sr4lhrrt

sr4lhrrt1#

使用number\ u format()函数。
例子:

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

输出:1000.00

yi0zb3m4

yi0zb3m42#

可以使用php数字格式。
例子:

echo number_format($res['sum_total'], 2, ',', '.')."€";

5000,00€
例子:

echo "€".number_format($res['sum_total'], 2, ',', '.');

€5000,00
例子:

echo number_format($res['sum_total'], 2, ',', '.');

5000,00
有关php数字格式的详细信息:http://php.net/manual/en/function.number-format.php

相关问题