My code I'm working on has a table db the data is 4.5 I wanted it to be 4.50 any help would be great.

here's my code:

<?php 
	
	  
  $con = mysql_connect("localhost", "root", "");
  
  if(!$con)  //If we can't connect then stop trying and say so
{
	die("Could not connect to server: ". mysql_error());
}
mysql_select_db("inventory_db", $con);
$query = "SELECT * FROM item_inventory";
echo "<table border='1' cellpadding='10' align='center' cellspacing='7'>
<tr>
<th>Item Name</th>
<th>Description</th>
<th>Price</th>
</tr>";
$result = mysql_query($query)
or die("Error " . mysql_error());

while($row = mysql_fetch_array($result))
  {
  	echo "<tr>";
  	echo "<td>" .  $row[ 'ItemName' ] . "</td>";
	echo "<td>" . $row['Description'] . "</td>";
	echo "<td>$" . $row['Price' ] . "</td>"; 	
 	echo "</tr>";
  }
echo "</table>";

mysql_close($con);

keep in mind that the price table date needs to have this pricison "#.##"

actually the table data does not require this precision, only the output data does
given the table column is returned as $row['price'] at line 26 in the original

$format_number = number_format($row['price'], 2, '.', ''); /* orignal number, 2 dec, dot sepaarated, nothing between thousands */
echo "<td>$".$format_number."</td>";

or

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

php.net reference

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.