George
George

Reputation: 31

PHP Currency display

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

Answers (7)

Christoph Diegelmann
Christoph Diegelmann

Reputation: 2044

you should have a look at number_format (http://php.net/manual/de/function.number-format.php)

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

results in £8,999,999

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

results in £8,999,999.00

Upvotes: 1

Marcin
Marcin

Reputation: 1024

I think that this is what you were looking for:

echo '£' . number_format($final_price);

Upvotes: 0

Paul Schwarz
Paul Schwarz

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

LordKarp
LordKarp

Reputation: 55

This should help you.

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

Check the money_format on php.net

Upvotes: 0

backtrack
backtrack

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

rukbat
rukbat

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

Jaak K&#252;tt
Jaak K&#252;tt

Reputation: 2656

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

Upvotes: 0

Related Questions