显示带有不同小数位数的货币


Show currencies with different numbers of decimal places

我有一个Wordpress网站,使用woocommerce和woocommerce货币切换插件。该网站在泰国以泰铢显示价格,在其他地方以美元显示价格。我希望购物车显示小数点后0位的泰铢和2位的美元。如果我将woocommerce设置为显示所有货币的小数点后2位,我是否可以添加一些功能来删除'。从每一个显示的。00฿的例子中?

这是我目前为止所做的…

function strip_zeros($baht) {
foreach($baht as $i) {
$baht= strtr($baht, ".00฿", "฿");
}
return $baht;
}
add_filter('the_content','strip_zeros');

试试这个,它对我来说很好

function strip_zeros($baht) {
foreach($baht as $i) {
$baht= sprintf("%02d",$baht);
}
return $baht;
}
add_filter('the_content','strip_zeros');

要点是sprintf("%02d",$baht);

简单的解决方案是将以下代码行添加到插件index.php文件中:

public $no_cents = array('THB');