2013-08-21 55 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);