PHP round to integer

后端 未结 6 450
再見小時候
再見小時候 2021-01-07 22:54

I want to round a number and I need a proper integer because I want to use it as an array key. The first \"solution\" that comes to mind is:

$key = (int)roun         


        
6条回答
  •  不要未来只要你来
    2021-01-07 23:32

    For My Case, I have to make whole number by float or decimal type number. By these way i solved my problem. Hope It works For You.

    $value1 = "46.2";
    $value2 = "46.8";
    
    
    // If we print by round()
    echo round( $value1 );    //return float 46.0
    echo round( $value2 );    //return float 47.0
    
    
    // To Get the integer value
    echo intval(round( $value1 ));   // return int 46
    echo intval(round( $value2 ));   // return int 47
    

提交回复
热议问题