doudi7782 2015-12-02 17:11
浏览 89

删除mysql中的尾随零(需要确切的查询示例)

Good evening. I am trying to remove trailing zeroes from mysql data that is displayed in a table (pic.1).

fragment of table (russian)

My code for the query is pretty much standard:

$query = "SELECT * FROM t_transport";
$result = mysql_query($query);


while( ($row = mysql_fetch_array($result)))
{


    echo "<tr>";
    echo "<td>".$row['date']."</td>";
    echo "<td>".$row['driver']."</td>";
    echo "<td>".$row['sortiment']."</td>";
    echo "<td>".$row['amount']."</td>";
    echo "<td>".$row['origin']."</td>";
    echo "<td>".$row['destination']."</td>";
    echo "<td>".$row['tours']."</td>";
    echo "<td>".$row['notes']."</td>";
    echo "<td>".$row['ts']."</td>";
    echo "</tr>";
}

The column with the numbers is the 'amount' one. Data is stored as decimal(10,3). Need to remove trailing zeroes, if such appear.

Now I understand, that there have been many solutions to this, I've read them all, but none of them works for me. Please help me altering my query.

Thanks in advance.

  • 写回答

2条回答 默认 最新

  • duanqiao1961 2015-12-02 17:22
    关注

    Use number_format() in php for this formatting task.

    echo "<td>" . number_format( $row['amount'], 0, '.', '' ) . "</td>";
    

    Here's a more complete q&a on stack overflow: How do I format numbers to have only two decimal places?

    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题