How can I trim decimal spaces of a query result?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Haitashi
    New Member
    • Jun 2007
    • 96

    #1

    How can I trim decimal spaces of a query result?

    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
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Is it a string or a number?

    Comment

    • Haitashi
      New Member
      • Jun 2007
      • 96

      #3
      It's a number. This is the query that populates that variable:

      Code:
      	<cfquery name="Variables.qTotal" datasource="#Variables.sDatasource#">
      		SELECT sum_completion = ((SUM(convert(real,is_complete)) / #Variables.qData.recordcount#) * 100)
      		FROM dbo.vw_activity_task_list
      		WHERE (class_section_id = #Session.oEnvironmentContext.sectionID#)
      		AND (SyStudentID = #Attributes.nStudentID#)
      		AND (can_grade = 1)
      	</cfquery>

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        Use the NumberFormat function with a mask of, say, "99.99".

        Comment

        • Haitashi
          New Member
          • Jun 2007
          • 96

          #5
          Perfect! That worked and I learned a new function. This will help me a lot. THANKS!

          Comment

          • acoder
            Recognized Expert MVP
            • Nov 2006
            • 16032

            #6
            You're welcome. Glad to help.

            Comment

            Working...