Max Bogatec Max Bogatec - 3 months ago 10
MySQL Question

PHP calculate with special chars

I'm working on an function that's getting Data from an Mysql DB and then it should calculate it. I've got the function like i want it, but my only Problem is that my Value in the DB looks like :


€12.345,67


But php thinks the dots are commas. So with the formating my result looks like:


25.000,00 + 40.000,00 =65.00


How it should look like:


25.000,00 + 40.000,00 = 65.000,00


I've already tried following parameter:

str_replace(',', '.', $value1);


It didn't work , so I'm asking you guys if someone has a clue how to do this.

My Code:

<?php

$con=mysqli_connect("localhost","root","pass","DB-Nane");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

$result = mysqli_query($con,"SELECT * FROM Fahrzeugverkauf WHERE Fahrzeugkonto = 2");
$rahmen = 230000;
while($row=mysqli_fetch_array($result)){
$total3 = $row['EKBrutto'];
$test +=$total3;
$belastung= $rahmen - $test;


}
//$res1 =

mysqli_close($con);

?>

<?php echo "Verfügbarer Rahmen: " .$rahmen;?> <br>
<?php echo "Belastung: " .$test;?> <br>
<?php echo "Verbliebenes Guthaben: " .$belastung;?>

Answer

Try it:

setlocale(LC_MONETARY, 'en_US');
echo money_format('%(#10n', $number) . "\n";
// ($        1,234.57)

from: http://php.net/manual/es/function.money-format.php