-2

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 Answers2

1

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?

Community
  • 1
  • 1
O. Jones
  • 103,626
  • 17
  • 118
  • 172
0

You can use this query:

$query = "SELECT * (CAST(`amount` AS CHAR)+0) as amountWOzero FROM t_transport";

You need to replace amount by the column with the trailing zeros and add amountWOzero to the php loop.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
yannik995
  • 307
  • 1
  • 12