【问题标题】:PHP Currency displayPHP 货币显示
【发布时间】:2013-08-21 08:36:47
【问题描述】:

我正在尝试在数字中显示一个 £ 符号和逗号以显示货币,但我不知道如何,这是我的代码,我的回显是 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>

【问题讨论】:

标签: php forms echo currency


【解决方案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 英镑

【讨论】:

    【解决方案2】:

    您可以使用 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
    

    【讨论】:

      【解决方案3】:

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

      【讨论】:

        【解决方案4】:
        $amount = '100000';
        setlocale(LC_MONETARY, 'en_GB');
        utf8_encode(money_format('%n', $amount));
        

        参考这个

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

        【讨论】:

          【解决方案5】:

          这应该对你有帮助。

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

          检查 php.net 上的 money_format

          【讨论】:

            【解决方案6】:

            看看这个,如果您还有问题,请告诉我。

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

            【讨论】:

              【解决方案7】:

              我认为这就是你要找的:

              回显'£'。 number_format($final_price);

              【讨论】:

                猜你喜欢
                • 2012-02-22
                • 1970-01-01
                • 1970-01-01
                • 1970-01-01
                • 1970-01-01
                • 1970-01-01
                • 1970-01-01
                • 1970-01-01
                • 2020-05-13
                相关资源
                最近更新 更多