0

通貨を表示するために£記号とカンマを数値で表示しようとしていますが、方法がわかりません。これが私が持っているコードで、£8,999,999ではなく8999999としてエコーされます

<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>
4

7 に答える 7

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
于 2013-08-21T08:40:04.820 に答える
1

number_format を確認する必要があります ( http://php.net/manual/de/function.number-format.php )

echo '&pound;'.number_format($final_price, 0);

結果は£8,999,999

echo '&pound;'.number_format($final_price, 2);

結果は£8,999,999.00

于 2013-08-21T08:43:01.797 に答える
0
$amount = '100000';
setlocale(LC_MONETARY, 'en_GB');
utf8_encode(money_format('%n', $amount));

これを参照

http://php.net/manual/en/function.money-format.php

于 2013-08-21T08:40:16.427 に答える
0

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

于 2013-08-21T08:39:20.313 に答える
0

This should help you.

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

Check the money_format on php.net

于 2013-08-21T08:42:20.170 に答える
0

これを見て、まだ質問がある場合はお知らせください。

http://php.net/manual/en/function.number-format.php

于 2013-08-21T08:43:01.570 に答える