Hi,
I have checked the web and here and can't seem to find my exact problem listed.
I have MYSQL ver 5.0.45 & PHP ver 5.2.4.
I am running a simple snippet of code below to gather data stored as decimal(10,2)
Running the query in MYSQL or phpMyadmin will return only one Sale price, correctly formatted as 12402.58 from my data.
The code below outputs 12403
With the following code the page displays the value as 12402.00.
I am a PHP/MYSQL newbie but I need the currency/decimal values to be displayed. I have also tried the following which also rounds up to the nearest dollar.
I am hoping it is something simple I have overlooked.
Thanks for any help you can offer.
Regards,
Peter.
Remember- It's nice to be important,
but it's important to be nice
I have checked the web and here and can't seem to find my exact problem listed.
I have MYSQL ver 5.0.45 & PHP ver 5.2.4.
I am running a simple snippet of code below to gather data stored as decimal(10,2)
Running the query in MYSQL or phpMyadmin will return only one Sale price, correctly formatted as 12402.58 from my data.
The code below outputs 12403
Code:
$sql = "select Sale from translog WHERE Sale > 9000 order by sale desc";
$result = mysql_query($sql);
while ($row = mysql_fetch_array($result, MYSQL_BOTH)) {
printf("Sale: %s", $row[0] . "<br>");
}
mysql_free_result($result);
With the following code the page displays the value as 12402.00.
Code:
$sql = "select Sale from translog WHERE Sale > 9000 order by sale desc";
$result = mysql_query($sql);
while ($row = mysql_fetch_array($result, MYSQL_BOTH)) {
printf("Sale: %s", number_format($row[0],2) . "<br>");
}
mysql_free_result($result);
I am a PHP/MYSQL newbie but I need the currency/decimal values to be displayed. I have also tried the following which also rounds up to the nearest dollar.
Code:
$sql = "select Sale from translog WHERE Sale > 9000 order by sale desc";
$result = mysql_query($sql);
while ($row = mysql_fetch_array($result, MYSQL_BOTH)) {
$formatted = sprintf("%01.2f", $row[0]);
echo $formatted . "<br>";
}
mysql_free_result($result);
I am hoping it is something simple I have overlooked.
Thanks for any help you can offer.
Regards,
Peter.
Remember- It's nice to be important,
but it's important to be nice