我正在研究一个从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;?>
试一试:
setlocale(LC_MONETARY, 'en_US');
echo money_format('%(#10n', $number) . "n";
// ($ 1,234.57)
:http://php.net/manual/es/function.money-format.php
尝试使用数字格式化器类,如
<?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)
?>