douqi3064 2014-05-14 08:41
浏览 45
已采纳

PHP禁用round_up

How can I disable the round up in my PHP script. If I sum up something it only displays the rounded Number.

<?php

$con=mysqli_connect("localhost","XXXX","XXXX","XXXX");
if (mysqli_connect_errno()) {
    echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM energrid WHERE ID = 1 ");

while($row = mysqli_fetch_array($result)) {
    $wert = $row['Wert'];
}
$result = mysqli_query($con,"SELECT * FROM energrid WHERE ID = 3 ");

while($row = mysqli_fetch_array($result)) {
    $wert1 = $row['Wert'];
}
mysqli_close($con);
echo "here we go.:";
echo $wert + $wert1;
?>

Ok, I guess I've found my mistake. The values are like 3,5 with a , instead of a .

How can I change that if these are values directly from the MySQL DB.?

  • 写回答

3条回答 默认 最新

  • doulun0651 2014-05-14 09:54
    关注

    1.You can use number_format function
    2.optimize your code -there is no need of while loop to do this

     <?php    
    $db = mysql_connect("localhost","username","password");  ///connect to mysql      
    if (!$db) {      
    // throw error if not connect      
     die("Database connection failed miserably: " . mysql_error());      
            }          
    $db_select = mysql_select_db("databasename",$db); ///select database      
    if (!$db_select) {      
    //database connection error      
    die("Database selection also failed miserably: " . mysql_error());       
    }      
    $sum=0;       
    $result = mysqli_query($db,"SELECT sum(wert) as sum FROM energrid WHERE ID in ('1','3') ");       
    $row = mysqli_fetch_array($result)       
    $sum =$row['sum'];       
    `enter code here`      
    
    echo number_format($sum,'number','.','');
    //where number-no. of  place you want to round off 
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题