警告:number_format()期望参数1为double,字符串为

时间:2015-01-15 15:34:09

标签: php

我收到以下错误:

  

警告:number_format()要求参数1加倍,在第200行.............中给出字符串

请告诉我解决方案。下面我将我的整个代码发布到第200行

<?php
function my_session_start() {
    session_start();
}

function escape($str) {
    $clean_str = ( get_magic_quotes_gpc ()) ? mysql_real_escape_string(stripslashes(trim($str))) : mysql_real_escape_string(trim($str));
    return $clean_str;
}

function _addslashes($str) {   
    $clean_str = ( get_magic_quotes_gpc ()) ? $str : addslashes($str);
    return $clean_str;
}

function clean($str) {
    $clean_str = stripslashes (trim($str));
    return $clean_str;
}

function checkbox_value($str) {
    if(isset($_POST[$str]) && $_POST[$str]=="on") return 1;
    return 0;    
}

function generate_random() {
    $str = md5(uniqid(rand(),1));
    return $str;
}

function html_link($str) {
    $str=correct_href($str);
    $ret='<a href="'.$str.'">'.$str.'</a>';
    return $ret;
}

function correct_href($str) {
    if(!trim($str)) return;
    if(strcmp(substr($str,0,7),"http://") && strcmp(substr($str,0,8),"https://")) $str="http://".$str;
    return $str;
}

function correct_number_format($str) {
    $app = new appearance();
    $appearance = $app->getAll();
    $decimals = $appearance['number_format_decimals']; 
    $point = $appearance['number_format_point'];  
    $separator = $appearance['number_format_separator']; 
    $ereg_str = "/^[0-9]*".$point."*[0-9]+".$separator."*[0-9]*$/";
    $ereg_str = str_replace(".", "\.", $ereg_str);
    if(preg_match($ereg_str, $str)) return 1;
    return 0;    
}

function correct_numeric($str) {
    global $appearance_settings;
    $point = $appearance_settings['number_format_point'];
    $separator = $appearance_settings['number_format_separator'];
    // replace 
    $str = str_replace($point,"#",$str);
    $str = str_replace($separator,"",$str);
    $str = str_replace("#",".",$str);
    return $str;
}

function correct_price($str) {
    global $appearance_settings;
    $point = $appearance_settings['price_format_point'];
    $separator = $appearance_settings['price_format_separator'];
    // replace 
    $str = str_replace($point,"#",$str);
    $str = str_replace($separator,"",$str);
    $str = str_replace("#",".",$str);
    return $str;    
}

1 个答案:

答案 0 :(得分:3)

在format_price($ str)或format_int($ str)中,我会做以下更改:

$result = number_format($str, $decimals, $point, $th_separator);

$result = number_format((int)$str, $decimals, $point, $th_separator);

如果数字包含便士使用

$result = number_format((float)$str, $decimals, $point, $th_separator);