我正在從一個MySQL數據庫獲取數據的函數,然後它應該計算它。我已經得到了功能像我想的那樣,但我的唯一的問題是,我在數據庫中值的樣子:PHP與特殊字符計算
€12.345,67
但是PHP認爲點是逗號。因此,與格式化我的結果是這樣的:
25.000,00 + 40.000,00 = 65.00
如何它應該看起來像:
25.000,00 + 40.000,00 = 65.000,00
我已經試過以下參數:
str_replace(',', '.', $value1);
它沒有工作,所以我問如果有人有線索如何做到這一點。
我的代碼:
<?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;?>
你試過到u你可以使用'number_format()'函數嗎? – SuperDJ
還沒有,我會試試看! –
嘗試它: http://php.net/manual/es/function.money-format.php – Vitorlui