Sign In | Register Now About Bytes | Help | Site Map
Connecting Tech Pros Worldwide

How can I trim decimal spaces of a query result?

Question posted by: Haitashi (Member) on April 30th, 2008 09:07 PM
I have a variable that contains results of a query. However, when the results (which calculates the grade average of a student) comes back with decimals, the display in really long like: 86.33333333.

If I get a result like the one above, I want the application to trim it down to just 86.33. How can I achieve this? I thought I could use "TRIM" but don't know how to go about that.

THANKS!
acoder's Avatar
acoder
Site Moderator
11,509 Posts
May 1st, 2008
10:08 AM
#2

Re: How can I trim decimal spaces of a query result?
Is it a string or a number?

Reply
Haitashi's Avatar
Haitashi
Member
77 Posts
May 1st, 2008
01:47 PM
#3

Re: How can I trim decimal spaces of a query result?
It's a number. This is the query that populates that variable:

Expand|Select|Wrap|Line Numbers
  1.     <cfquery name="Variables.qTotal" datasource="#Variables.sDatasource#">
  2.         SELECT sum_completion = ((SUM(convert(real,is_complete)) / #Variables.qData.recordcount#) * 100)
  3.         FROM dbo.vw_activity_task_list
  4.         WHERE (class_section_id = #Session.oEnvironmentContext.sectionID#)
  5.         AND (SyStudentID = #Attributes.nStudentID#)
  6.         AND (can_grade = 1)
  7.     </cfquery>

Reply
acoder's Avatar
acoder
Site Moderator
11,509 Posts
May 1st, 2008
02:30 PM
#4

Re: How can I trim decimal spaces of a query result?
Use the NumberFormat function with a mask of, say, "99.99".

Reply
Haitashi's Avatar
Haitashi
Member
77 Posts
May 1st, 2008
07:20 PM
#5

Re: How can I trim decimal spaces of a query result?
Perfect! That worked and I learned a new function. This will help me a lot. THANKS!

Reply
acoder's Avatar
acoder
Site Moderator
11,509 Posts
May 2nd, 2008
08:16 AM
#6

Re: How can I trim decimal spaces of a query result?
You're welcome. Glad to help.

Reply
Reply
Not the answer you were looking for? Post your question . . .
189,162 Experts ready to help you find a solution.
Sign up for a free account, or Login (if you're already a member).

Latest Articles: Read & Comment
Top Coldfusion Forum Contributors