我正在研究Zen Cart中的某些内容,并且我不希望.00显示价格。 我以为我解决了该问题通过做检查数字是否以.00结尾使用php
$price=number_format($special_price,2,'.','');
但禅车具有如下功能:添加所需的货币符号的前面或
$currencies->format($price)
的问题是,这个功能增加了数回.00回到价值!
该函数的代码是
$format_string = $this->currencies[$currency_type]['symbol_left'] . number_format(zen_round($number * $rate, $this->currencies[$currency_type]['decimal_places']), $this->currencies[$currency_type]['decimal_places'], $this->currencies[$currency_type]['decimal_point'], $this->currencies[$currency_type]['thousands_point']) . $this->currencies[$currency_type]['symbol_right'];
如果我复制该函数,这样我有$ currencies-> FORMAT2($价格)并将其更改为
$format_string = $this->currencies[$currency_type]['symbol_left'] . number_format(zen_round($number * $rate, $this->currencies[$currency_type]['decimal_places']), $this->currencies[$currency_type]['0'], $this->currencies[$currency_type]['decimal_point'], $this->currencies[$currency_type]['thousands_point']) . $this->currencies[$currency_type]['symbol_right'];
则反而会加重货币符号不加小数点后退。当然,当你有49.50这样的价格时,它就是四舍五入到最高达到50
我尝试了
$cur_price=$currencies->format($special_price);
$price=str_replace(".00", "", (string)number_format ($cur_price, 2, ".", ""));
它背后的思想是,我可以先应用货币符号,然后删除小数,如果它们是.00,但这导致价格应该是空白。
我要么需要找到一个方法来检查,如果
$price
在.00结束,所以我可以有条件地currencies- $>格式()或$ currencies-> FORMAT2(),或者我需要修改原始函数,如果它为.00,则不要将小数位放在适当位置,但在其他时间允许使用。
可以结束第一轮数到小数点后两位的东西后,再次运行呢? – atoms
@泰勒塞巴斯蒂安,工作完美。谢谢。 –