Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/237.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 如何在细枝中隐藏LocalizedCurrent筛选器的小数部分_Php_Symfony_Twig_Intl - Fatal编程技术网

Php 如何在细枝中隐藏LocalizedCurrent筛选器的小数部分

Php 如何在细枝中隐藏LocalizedCurrent筛选器的小数部分,php,symfony,twig,intl,Php,Symfony,Twig,Intl,我正在使用过滤器以多种语言格式化价格 网站。因为这是房价,所以我不需要小数部分 除了使用replace过滤器外,我找不到如何隐藏它。我想知道是否有更好的方法,因为使用replace将意味着我必须在英语中替换一个点,在法语中替换一个逗号等等 我也不能使用某种形式的substr,因为美元符号可以在值之前或之后 我尝试将int而不是float传递给过滤器,但它只是默认为.00 谢谢 使用: '%.0i'中的.0是右侧精度 您可能需要向细枝扩展添加筛选器。如果你需要帮助,请告诉我 编辑: 查看intl扩

我正在使用过滤器以多种语言格式化价格 网站。因为这是房价,所以我不需要小数部分

除了使用
replace
过滤器外,我找不到如何隐藏它。我想知道是否有更好的方法,因为使用
replace
将意味着我必须在英语中替换一个点,在法语中替换一个逗号等等

我也不能使用某种形式的substr,因为美元符号可以在值之前或之后

我尝试将int而不是float传递给过滤器,但它只是默认为
.00

谢谢

使用:

'%.0i'
中的
.0
是右侧精度

您可能需要向细枝扩展添加筛选器。如果你需要帮助,请告诉我

编辑:

查看intl扩展,它似乎从
NumberFormatter
类调用
formatCurrency
方法,该类反过来调用私有
roundCurrency
,该类最终执行以下操作:

private function roundCurrency($value, $currency)
{
    $fractionDigits = Intl::getCurrencyBundle()->getFractionDigits($currency);

    // ...

    // Round with the formatter rounding mode
    $value = $this->round($value, $fractionDigits);

    // ...
}
但试图追踪
$fractionDigits
值的来源将在层次结构上再增加两个类,并变得像这样神秘:

public function getFractionDigits($currency)
{
    try {
        return $this->reader->readEntry($this->path, 'meta', array('Meta', $currency, static::INDEX_FRACTION_DIGITS));
    } catch (MissingResourceException $e) {
        return $this->reader->readEntry($this->path, 'meta', array('Meta', 'DEFAULT', static::INDEX_FRACTION_DIGITS));
    }
}

因此,可以让您当前的分机进行舍入,但我可能会使用我自己的筛选器,因为它似乎更容易,而且我可以动态指定精度。

尝试使用小数点后0位的数字\u格式筛选器,但它不会在其区域设置对应的位置上添加货币符号,100$/$100试试圆形过滤器。看起来可能就是这个,我今晚会测试一下,然后再给你回复
public function getFractionDigits($currency)
{
    try {
        return $this->reader->readEntry($this->path, 'meta', array('Meta', $currency, static::INDEX_FRACTION_DIGITS));
    } catch (MissingResourceException $e) {
        return $this->reader->readEntry($this->path, 'meta', array('Meta', 'DEFAULT', static::INDEX_FRACTION_DIGITS));
    }
}