我试图在数字中显示一个£符号和逗号来显示货币,但我不确定如何显示,这是我的代码,它是899999,而不是899999英镑
<div id="form">
<form action="index.php" method="post">
<center> <input type="text" name="percent" id="percent" />
<input type="submit" /> </center>
</form>
<center>
<?php
$percent=$_POST['percent'];
$total = 8999999;
/*calculation for discounted price */
$discount_value=$total/100*$percent;
$final_price = $total - $discount_value;
echo $final_price;
?>
</center>
</div>
您应该查看number_format(http://php.net/manual/de/function.number-format.php)
echo '£'.number_format($final_price, 0);
导致899999英镑
echo '£'.number_format($final_price, 2);
导致899999.00英镑
您可以使用money_format函数。正如你在这里看到的http://php.net/manual/en/function.money-format.php您可以用您的货币设置数字格式:
// let's print the international format for the en_US locale
setlocale(LC_MONETARY, 'en_US');
echo money_format('%i', $number) . "'n";
// USD 1,234.56
尝试echo '£'.number_format($final_price,2,",",".");
$amount = '100000';
setlocale(LC_MONETARY, 'en_GB');
utf8_encode(money_format('%n', $amount));
请参阅此
http://php.net/manual/en/function.money-format.php
这应该会对您有所帮助。
<?php
echo "£".money_format('%.2n', $final_price);
?>
检查php.net 上的money_format
看看这个,如果您还有问题,请告诉我。
http://php.net/manual/en/function.number-format.php
我想这就是您想要的:
echo"£"。number_format($final_price);