Kara Kara - 3 years ago 174
PHP Question

Php numberformatter displaying zero

I'm trying to display currency in invoice in words. Why is $total value displaying as zero / zero / zero ?

<td class="no-borders" colspan="2">
<table class="totals">
<?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']); ?>

<?php endforeach; ?>

Answer Source

Numberformatter wants numbers not strings.

20 is a number. €20 is a string.

$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


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download