2013-08-21 50 views
0

我试图在多个显示£标志和逗号与显示货币,但我不知道怎么样,这里是我的代码有回声的它为8999999,而不是£8999999PHP货币显示

<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> 
+1

[number_format()](http://www.php.net/manual/en/function.number-format.php)或[money_format()](http://www.php.net/)手动/ EN/function.money-format.php)或[冲刺()](http://www.php.net/manual/en/function.sprintf.php)的[基本的PHP形式帮助 –

+0

可能重复(货币显示)](http://stackoverflow.com/questions/345704/basic-php-form-help-currency-display) – hakre

回答

0

试试echo '£'.number_format($final_price,2,",",".");

1

您可以使用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 
0

这会帮助你。

<?php 
    echo "&pound".money_format('%.2n', $final_price); 
?> 

检查php.net

0

我认为这是你在找什么:

回波 '£'。 number_format($ final_price);