"Rounding"

1. Senior Member
Join Date
Dec 1969
Posts
413

## "Rounding"

How can I chop off all but one or two decimals in my recordset?<BR>I am doing this...<BR><BR>strSQL = "SELECT AVG(field) AS FIELD FROM tblSurvey"<BR>Set RS = Conn.Execute(strSQL)<BR><BR>When I do...<BR>&#060;html&#062;<BR>Average of field &#060;%=rs("FIELD")%&#062;<BR>&#060;/html&#062;<BR><BR>...I get a long decimal...how can I truncate everything after, say, 2 decimals?<BR><BR>I looked up how to round in the FAQ&#039;s, but the links were broken...

2. God
Senior Member
Join Date
Dec 1969
Posts
18,177

## Round() or FormatNumber()

And, there is a link to the VBScript documentation to your left.

3. Member
Join Date
Dec 1969
Posts
81

## RE: Rounding

Average of field &#060;%=Round(rs("Field"), x)%&#062;<BR>where x is the number of decimal places you want.

4. Senior Member
Join Date
Dec 1969
Posts
2,854

## Formatnumber(rs"field"), 2) <nt>

.

5. Senior Member
Join Date
Dec 1969
Posts
413

## thanks all <eop>

.

6. Senior Member
Join Date
Dec 1969
Posts
413

## ONE MORE THING

When I loop thru a recordset, how can I get rid of anything that is non-numeric and then subtract that from the number of...wait, let me explain...<BR><BR>I&#039;m doing a survey, and my boss wants N/A to be an option for a couple of questions...thus screwing up the SELECT AVG(field) FROM tbl...etc. <BR><BR>Is there a fix for this?

7. Senior Member
Join Date
Dec 1969
Posts
3,195

## RE: ONE MORE THING

How about setting the value on table to NULL if they select N/A?

8. Senior Member
Join Date
Dec 1969
Posts
413

## I had just done that

and was going to post that I had figured it out...thanks anyway

9. Senior Member
Join Date
Dec 1969
Posts
413

## FYI...none of that stuff worked

I still couldn&#039;t take an average if there was an empty or NULL table field. So what I did was say...If the user entered N/A then set that value to 6. Then my SQL statement was like...<BR><BR>strSQL = "SELECT AVG(field) FROM tblTable WHERE Field &#060;= &#039;5&#039;<BR><BR>anyway, it works now...just letting you all know...<BR>

10. Senior Member
Join Date
Dec 1969
Posts
3,195

## Just exclude NULLs from

your resultset<BR><BR>strSQL = "SELECT AVG(field) FROM tblTable WHERE Field IS NOT null"<BR><BR>

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•