Php numberformatter显示零

时间:2017-09-30 20:05:16

标签: php number-formatting

我试图用单词在发票中显示货币。为什么$ total值显示为零/零/零?

    <td class="no-borders" colspan="2">
            <table class="totals">
                <tfoot>
                    <?php foreach( $this->get_woocommerce_totals() as $key => $total ) : ?>
                    <tr class="<?php echo $key; ?>">
                        <td class="no-borders"></td>

                        <th class="description"><?php echo $total['label']; ?></th>

                        <td class="price"><span class="totals-price"><?php echo $total['value']; ?></span></td>

                        <?php $f = new NumberFormatter("lv", NumberFormatter::SPELLOUT);
                        echo $f->format($total['value']); ?>

                    </tr>
                    <?php endforeach; ?>

1 个答案:

答案 0 :(得分:1)

Numberformatter想要的数字不是字符串。

20是一个数字。 €20是一个字符串。

$f = new NumberFormatter("en", NumberFormatter::SPELLOUT);
echo $f->format("20.00");  // twenty or divdesmit in lv
echo "\n";
echo $f->format("€20.00");  // zero or nulle in lv
echo "\n";
echo $f->format(str_replace("€", "", "€20.00")); // str_replace to remove euro sign

https://3v4l.org/eA6u9