Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/294.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php数字格式显示零_Php_Number Formatting - Fatal编程技术网

Php数字格式显示零

Php数字格式显示零,php,number-formatting,Php,Number Formatting,我试图用文字显示发票中的货币。为什么$total值显示为零/零/零 <td class="no-borders" colspan="2"> <table class="totals"> <tfoot> <?php foreach( $this->get_woocommerce_totals() as $key => $total ) : ?

我试图用文字显示发票中的货币。为什么$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; ?>

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

如果不是零,$total['value']的值是多少?您的区域设置代码必须是“lv-lv”,并且必须存在于您的系统中@安德烈亚斯,当我把它变成20.00欧元时。有没有办法把这个值转换成int,这样欧元符号就被忽略了?str_replace仍然保存欧元符号,可能是因为它作为货币而不是字符串?它怎么可能是货币?据我所知,没有称为currency的数据类型。你有string,integer,float,bool等等,你能复制粘贴你使用的代码吗?替换带有str_的行和带有numberformatter回声的行(如果不相同)。当然,你也可以
var_dump($total['value'])并将输出复制到我?它应该说明“值”是什么数据类型@Karavar_dumb以字符串(118)“20.00欧元”的形式出现。我基本上是在尝试为货币添加拼写形式(wordpress插件woocomerce)@Andreas第一个文件的代码: