formatting decimals?

1. Member
Join Date
Dec 1969
Posts
67

## formatting decimals?

How can I format a decimal number to the nearest 1000th?<BR><BR>example: 0.2562321<BR>I want: 0.256<BR><BR>

2. Senior Member
Join Date
Dec 1969
Posts
820

## RE: formatting decimals!

You want...<BR><BR>mynum = formatnumber (mynum, 3)

3. Member
Join Date
Dec 1969
Posts
50

## RE: formatting decimals?

Try:<BR><BR> Format Function<BR><BR><BR>

4. Senior Member
Join Date
Dec 1969
Posts
820

## Won't work!

VBS does not support the format function. Formatnumber will work.

5. Member
Join Date
Dec 1969
Posts
65

## RE: formatting decimals?

in sql you can do it:<BR>select str(0.2562321,5,4)

6. Member
Join Date
Dec 1969
Posts
67

## RE: It worked....but

Now i&#039m trying to format the AVG of the previously fomatted numbers. <BR> Example: .234<BR> .334<BR> -----<BR> i&#039m gettin .284356 <BR> I&#039m getting this error msg:<BR><BR> Microsoft VBScript runtime error &#039 800a000d&#039 <BR> Type mismatch: &#039formatnumber&#039 <BR><BR>Can I not use &#039formatnumber&#039 more than once...?<BR>

7. Senior Member
Join Date
Dec 1969
Posts
820

## RE: It worked....but

I think you need to cast the results...<BR><BR>formatnumber ((csng(formatnumber (.234333, 3)) + csng(formatnumber (.348234567, 3)))/2, 3) = 0.291

8. Member
Join Date
Dec 1969
Posts
67

## RE: Isn't there an easier way

Isn&#039t there an easier way...I have 16 of these to add up and average out...?

9. Member
Join Date
Dec 1969
Posts
67

## RE: Isn't there an easier way

Oh yeah, and the numbers are coming from a Database so I can&#039t <BR>hard code&#039em...

10. Senior Member
Join Date
Dec 1969
Posts
820

## RE: Isn't there an easier way

Well, I&#039d just put them in a loop...<BR><BR>Dim i, countx, sumx, avex, rsarray<BR>&#039select your values<BR>rsarray = rs.getrows<BR><BR>for i = 0 to ubound (rsarray, 2)<BR>countx = countx + 1<BR>sumx = sumx + CSng (formatnumber (numberarray (i), 3))<BR>next<BR>avex = sumx = formatnumber (sumx / CLng (countx), 3)<BR><BR>Comment: why do you want to round the individual values anyway? It will give you an incorrect average. You could also just select the average out of the database directly and do away with all this nonsense.

#### Posting Permissions

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