我正在研究一个从MySQL数据库获取数据的函数,然后它应该计算它。我有像我想要的功能,但我唯一的问题是我在数据库中的价值如下:
€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;?>
答案 0 :(得分:0)
试一试:
setlocale(LC_MONETARY, 'en_US');
echo money_format('%(#10n', $number) . "\n";
// ($ 1,234.57)
答案 1 :(得分:0)
尝试使用Number Formatter Class之类的,
<?php
$a = new \NumberFormatter("it-IT", \NumberFormatter::CURRENCY);
echo $a->formatCurrency(12345, "USD") . "<br>"; // outputs $ 12.345,00 and it is formatted using the italian notation (comma as decimal separator)
?>