欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程资源 > 编程问答 >内容正文

编程问答

【ECSHOP】格式化商品价格

发布时间:2025/4/14 编程问答 46 豆豆
生活随笔 收集整理的这篇文章主要介绍了 【ECSHOP】格式化商品价格 小编觉得挺不错的,现在分享给大家,帮大家做个参考.
/*** 格式化商品价格** @access public* @param float $price 商品价格* @return string*/ function price_format($price, $change_price = true) {if($price===''){$price=0;}if ($change_price && defined('ECS_ADMIN') === false){switch ($GLOBALS['_CFG']['price_format']){case 0:$price = number_format($price, 2, '.', '');break;case 1: // 保留不为 0 的尾数$price = preg_replace('/(.*)(\\.)([0-9]*?)0+$/', '\1\2\3', number_format($price, 2, '.', ''));if (substr($price, -1) == '.'){$price = substr($price, 0, -1);}break;case 2: // 不四舍五入,保留1位$price = substr(number_format($price, 2, '.', ''), 0, -1);break;case 3: // 直接取整$price = intval($price);break;case 4: // 四舍五入,保留 1 位$price = number_format($price, 1, '.', '');break;case 5: // 先四舍五入,不保留小数$price = round($price);break;}}else{$price = number_format(floatval($price), 2, '.', '');}return sprintf($GLOBALS['_CFG']['currency_format'], $price); }

 

转载于:https://www.cnblogs.com/chenjiacheng/p/7115300.html

总结

以上是生活随笔为你收集整理的【ECSHOP】格式化商品价格的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。