我试图用单词在发票中显示货币。为什么$ 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; ?>
答案 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