If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > General > New Members & Introductions > Very novice question

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-25-11, 14:54
millers millers is offline
Registered User
 
Join Date: Feb 2011
Posts: 5
Very novice question

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.14

Here'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 result
while($row = mysql_fetch_array($result)){
echo "Total cash back to school so far £ ". $row['SUM(product_price)/100*10'];
echo "<br />";

}

?>
Reply With Quote
  #2 (permalink)  
Old 02-25-11, 15:26
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
Quote:
Originally Posted by millers View Post
... I'm trying to round the following query result to 2 dec places.
may i suggest using the ROUND function

__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 02-25-11, 15:32
millers millers is offline
Registered User
 
Join Date: Feb 2011
Posts: 5
Can't get the syntax right

Hi, thanks ..

I've tried: SELECT ROUND(SUM(product_price)/100*10,2)...
in the query but that just breaks the 'print out result'. I get £ ....
Do I have to alter that section also?
Reply With Quote
  #4 (permalink)  
Old 02-25-11, 15:38
Teddy Teddy is offline
Purveyor of Discontent
 
Join Date: Mar 2003
Location: The Bottom of The Barrel
Posts: 6,075
Are you sure you wanted to divide by 1000?
__________________
oh yeah... documentation... I have heard of that.

*** What Do You Want In The MS Access Forum? ***
Reply With Quote
  #5 (permalink)  
Old 02-25-11, 15:43
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
Quote:
Originally Posted by Teddy View Post
Are you sure you wanted to divide by 1000?
he's dividing by 10, teddy

dividing by 1000 would be foo/(100*10)

millers, you should use a column alias in your query, it will make displaying the result simpler
Code:
SELECT ROUND(...) AS rounded ...

echo "Total cash back to school so far £ ". $row['rounded'];
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #6 (permalink)  
Old 02-25-11, 15:45
millers millers is offline
Registered User
 
Join Date: Feb 2011
Posts: 5
Novice looking for help

I admit I'm a complete novice. That's why I'm here looking for help. This is a bit of a one-off for me and I'm not planning on becoming an expert. I've looked at the documentation, but just can't seem to get the syntax right.

And, no! I don't want to divide by 1000 - I thought I was taking 10% off!!
Reply With Quote
  #7 (permalink)  
Old 02-25-11, 16:07
millers millers is offline
Registered User
 
Join Date: Feb 2011
Posts: 5
Thanks

OK, many thanks guys, I'll give it my best ..
Reply With Quote
  #8 (permalink)  
Old 02-25-11, 16:23
millers millers is offline
Registered User
 
Join Date: Feb 2011
Posts: 5
Thanks r937 --- It worked
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On