国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 網站 > 建站經驗 > 正文

ecshop在php5.3以上的錯誤number_format() 解決方案

2024-04-25 20:39:49
字體:
來源:轉載
供稿:網友

ecshop在php5.3上報錯:

Warning: number_format() expects parameter 1 to be double, string given inD:/*******/includes/lib_common.php on line 959

Warning: number_format() expects parameter 1 to be double, string given inD:/*******/includes/lib_common.php on line 959

這個錯誤是ecshop 在php5.3以上的報錯

原因是配送插件里面的免費額度為0,ec本身的bug導致了$price的值為空值,直接調用number_format出現了錯誤。

解決方案如下:

/**

* 格式化商品價格

*

* @access public

* @param float $price 商品價格

* @return string

*/

function price_format($price, $change_price = true)

{

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

{

if(!$price){

$price = 0;

}

$price = number_format($price, 2, '.', '');

}

return sprintf($GLOBALS['_CFG']['currency_format'], $price);

}

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 株洲县| 顺平县| 耿马| 富蕴县| 来安县| 嘉禾县| 启东市| 清远市| 纳雍县| 江口县| 黄平县| 平邑县| 黎城县| 定边县| 丘北县| 济宁市| 宣武区| 上思县| 泊头市| 都昌县| 耒阳市| 图们市| 雅江县| 大荔县| 拉萨市| 张家界市| 上思县| 北海市| 海门市| 江孜县| 百色市| 历史| 永善县| 沾化县| 平陆县| 株洲市| 松溪县| 庆元县| 涟水县| 宁夏| 都匀市|