是否可以将num rows(Integer)作为十进制回显?

时间:2017-10-20 07:07:03

标签: php

我想做一些echo Integer,但是把它显示为十进制数..

在这种情况下$ rows [0] = 9

但是我需要将其显示为0.09才有可能吗?

<?php

$con = new mysqli("localhost", "root", "") or die("not connected");

$mydb = mysqli_select_db($con, "ehh") or die("no db found");


if(!$con){
die('dont connect '. mysqli_connect_error());
}


if(!$mydb){
die('dont connect '. mysqli_connect_error());
}



$query = "SELECT COUNT(*) FROM ohh";
$result = mysqli_query($con,$query);
$rows = mysqli_fetch_row($result);
$yeah = $rows[0];


echo $yeah;

mysqli_close($con);

?>

2 个答案:

答案 0 :(得分:2)

通用(带有N位数的数字)

$number = $rows[0];
$lenght = strlen($number);
$extra_decimals = 1; 
$divisor = str_pad('1',$lenght + $extra_decimals ,'0',STR_PAD_RIGHT);
$result = $number / intval($divisor);
echo $result;

答案 1 :(得分:1)

在SQL中

select ( count(*)/100.0 ) from ohh

或者在PHP中(不是两者同时)

echo $yeah / 100;