MYSQL echo向我显示十进制和非十进制

时间:2018-11-06 10:27:24

标签: php mysql

我从mysql数据库获取数据。 3个回声中有2个在数字后面显示了一个点。例如:  32500.00€ 第三个没有告诉我。 Jusdt: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€

2 个答案:

答案 0 :(得分:2)

使用number_format()函数。

示例:

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

输出:1,000.00

答案 1 :(得分:2)

您可以使用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