Reputation: 186
I take data from a mysql databae. 2 from 3 echos show me a dot behind the number. For example: 32500.00€ the third doesnt show me that. Jusdt: 32500. In the best case i want this format in the echo: 32.500.00€
Here is my code:
$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'];
The output is the following:
<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>
and this is the result:
Location NR NR NR 39500€ 28000.00€ 11500.00€
Upvotes: 0
Views: 152
Reputation: 1792
You can use php number formatting.
Example:
echo number_format($res['sum_total'], 2, ',', '.')."€";
5000,00€
Example:
echo "€".number_format($res['sum_total'], 2, ',', '.');
€5000,00
Example:
echo number_format($res['sum_total'], 2, ',', '.');
5000,00
More information about PHP number format: http://php.net/manual/en/function.number-format.php
Upvotes: 2
Reputation: 970
Use number_format() function.
Example:
$number = 1000;
echo number_format($number, 2);
output: 1,000.00
Upvotes: 2