Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
millers
Starting Member
2 Posts |
Posted - 2011-02-25 : 14:32:55
|
| Hi guys. I really shouldn't be messin' with this stuff at my level of knowledge, but ... I'm trying to round the following query result to 2 dec places. Typical output is currently 8.14000002 and I'm after £8.14Here's my code so far - hope it's not too bad!$connection = mysql_connect($host,$user,$password) or die("Could not connect: ".mysql_error());mysql_select_db($database,$connection) or die("Error in selecting the database:".mysql_error());$query = "SELECT SUM(product_price)/100*10 FROM ps_order_detail WHERE product_supplier_reference = 'test-sch-ch-hood-2011' or product_supplier_reference = 'test-sch-girl-blazer-2011'"; //add supplier references$result = mysql_query($query) or die(mysql_error());// Print out resultwhile($row = mysql_fetch_array($result)){ echo "Total cash back to school so far £ ". $row['SUM(product_price)/100*10']; echo "<br />"; }?> |
|
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2011-02-25 : 14:38:00
|
| SQLTeam is a Microsoft SQL Server site, we don't handle MySQL questions. There's a MySQL forum over at http://dbforums.com/That being said, there should be a ROUND() function that lets you specify how many decimal places you want:SELECT ROUND(SUM(product_price)/100*10, 2) FROM ps_order_detail ...; |
 |
|
|
millers
Starting Member
2 Posts |
Posted - 2011-02-25 : 14:41:39
|
| OK. Sorry for being in the wrong forum - and many thanks for the answer just the same! |
 |
|
|
|
|
|