带小数点分隔符的PHP返回价格

问题描述

您能帮我解决一下如何自定义以下已添加wordpress / Woocommerce的代码输出吗?我希望将返回值(常规价格和销售价格)用千位后的小数点分隔符(点)分隔,例如“ 1.200”。

代码

function sr_change_variable_price($price,$product){
    $html_tag = '<span id="reg_price">%s</span><span id="sale_price">%s</span>';
    if($product->is_type('variable') AND !is_product()){
        $test = $product->get_variation_regular_price('min') . ' Ft' ;
        $min = $product->get_variation_sale_price('min') . ' Ft';
        return(sprintf($html_tag,$test,$min));
    }elseif($product->is_type('variable') AND is_product()){
        return('');
    }else
    {return $price;  // other cases
    }
}
add_filter('woocommerce_get_price_html','sr_change_variable_price',10,2);

非常感谢您的帮助

解决方法

您可以简单地使用number_format

示例:

$price = number_format(1200,'','.');
echo $price; // outputs 1.200

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...