Reputation: 31
I am trying to display a £ sign and commas with in a number to show currency but i'm not sure how to, here is the code i have that echo's it as 8999999 instead of £8,999,999
<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>
Upvotes: 0
Views: 1778
Reputation: 2044
you should have a look at number_format (http://php.net/manual/de/function.number-format.php)
echo '£'.number_format($final_price, 0);
results in £8,999,999
echo '£'.number_format($final_price, 2);
results in £8,999,999.00
Upvotes: 1
Reputation: 1024
I think that this is what you were looking for:
echo '£' . number_format($final_price);
Upvotes: 0
Reputation: 1958
Take a look at this and let me know if you still have questions.
http://php.net/manual/en/function.number-format.php
Upvotes: 0
Reputation: 55
This should help you.
<?php
echo "£".money_format('%.2n', $final_price);
?>
Check the money_format on php.net
Upvotes: 0
Reputation: 8144
$amount = '100000';
setlocale(LC_MONETARY, 'en_GB');
utf8_encode(money_format('%n', $amount));
refer this
http://php.net/manual/en/function.money-format.php
Upvotes: 0
Reputation: 49
You can use money_format function. As you can see here http://php.net/manual/en/function.money-format.php you can format number in your currency:
// 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
Upvotes: 1