简体   繁体   English

PHP货币显示

[英]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 我试图在一个数字中显示一个£符号和逗号来显示货币,但我不知道该怎么做,这里的代码我的回音是8999999而不是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>

You can use money_format function. 你可以使用money_format函数。 As you can see here http://php.net/manual/en/function.money-format.php you can format number in your currency: 正如您在此处所见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

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

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

results in £8,999,999 结果是8,999,999英镑

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

results in £8,999,999.00 结果是£8,999,999.00

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

$amount = '100000';
setlocale(LC_MONETARY, 'en_GB');
utf8_encode(money_format('%n', $amount));

refer this 参考这个

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

This should help you. 这应该对你有帮助。

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

Check the money_format on php.net 检查php.net上的money_format

Take a look at this and let me know if you still have questions. 看看这个,如果您还有疑问,请告诉我。

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

I think that this is what you were looking for: 我认为这就是你要找的东西:

echo '£' . 回声'£'。 number_format($final_price); number_format($ final_price);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM