-4
I have the following code
<?php
ini_set('display_errors', true);
error_reporting(E_ALL);
include_once("con.php");
$pdo = conectar();
$id_empresa = $_GET['id_empresa'];
$data = $_GET['data'];
$tipo = "ENT";
$valorTotalE = 0;
$valorTotalEntradas=$pdo->prepare('SELECT valor FROM importa
WHERE data=:data
AND id_empresa=:id_empresa
AND tipo=:tipo');
$valorTotalEntradas->bindValue('id_empresa', $id_empresa);
$valorTotalEntradas->bindValue('data', $data);
$valorTotalEntradas->bindValue('tipo', $tipo);
$valorTotalEntradas->execute();
while ($linha=$valorTotalEntradas->fetch(PDO::FETCH_ASSOC)) {
$valor = $linha['valor'];
$valorTotalE = $valorTotalE + $valor;
$valorTotalE = number_format($valorTotalE,2,',','.');
$return = array(
'valorTotalE' => $valorTotalE
);
}
echo json_encode($return);
?>
This command line "$valueTotalE = number_format($valueTotalE,2,','.');" formats the value in 9,999.99, however, it does this that appears in the image below
For me the image seems correct with the example
9.999,99
, point separates mile and comma separates the pennies. What exactly you expected to occur?– Guilherme Nascimento
Where do you ask your question? What’s wrong ? =(
– Rafael Salomão
@Guilhermenascimentop. note that the value of 16,269.70 is to be the sum of the 4 values above.
– GustavoSevero
@Rafaelsalomão, same answer I gave to Guilherme.
– GustavoSevero
You are trying to add strings with non-numeric format, money/currency format is not number.
– Guilherme Nascimento
I make my own the words of @Guilhermenascimentop., you need to convert the value to float
– Diéfani Favareto Piovezan
If I do not place the line $valueTotalE = number_format($valueTotalE,2,','.'); the value appears added, but without this formatting.
– GustavoSevero