All right, I have code that pulls out of the MySQL database, and it returns a decimal with four decimal places. The problem is when the values are displayed in the php I would like them to have only 2 decimal places, and just truncate the other 2, because anytime all four decimal places are needed they are pulled directly from the DB and not shown on the page. Any help as far as functions, or links to needed functions would be greatly appreciated, thank you.
Here is how the Code goes:
Code: Select all
while($myrow = mysql_fetch_array($sidrows))
{
$dbsid = $myrow["sid"];
$dbsymbol = $myrow["symbol"];
$dbsname = $myrow["sname"];
$dbcurr = $myrow["current_price"];
$dbstart = $myrow["start_price"];
echo "<tr><td>$dbsymbol</td> ";
echo "<td><a href='stockdesc.php?stocksymbol=$dbsymbol'>$dbsname</a></td>";
if($dbcurr > $dbstart)
{
echo "<td><font color="#00FF00">$dbcurr</font></td>";
}
else if($dbcurr < $dbstart)
{
echo "<td><font color="#FF0000">$dbcurr</font></td>";
}
else if($dbcurr == $dbstart)
{
echo "<td>$dbcurr</td>";
}
// display more information, not relevant
$dbcurr is the current stock price in the database, which is the number with 4 decimal places, but since its money, and money is normally measured in 2 decimal places, I would like it to be shown in only 2 decimal places with the other two truncated. Once again, thanks for any help you may offer.