limiting decimal places in query result

M

Matthew

Hello, I have a database which has a query with a string like Sum([person])/count(*)*100. When I go to display the results of the query on my page it lools like this <%=rs("person")%>% the only problem I am having is that when it is not an even number of votes I get a really long decimal number. Is there a simple way in asp to make the results round to 1 decimal place or just cut it off after a certain number of digits or is this a strictly MS Access thing. Either way thanks for your help. Matt
 
B

Bill Schroyer

Try this:

This handy function below will round off numbers to two
decimal places (perfect for working with variables related
to currency values) however, if the resulting number only
has one digit following the decimal place, it doesn't
append a "0" to the end of the result.

For instance, if the number being rounded is "1.1231" the
result will be "1.12" but if the number to be rounded
is "1.2" then the result will be "1.2" where it should
be "1.20".

Any help achieving this would be grand.

Code:
function TwoDP(strNum)
Dim x
x = Instr(strNum,".")
TwoDP = Mid(strNum, 1, x + 2)
end function

http://forums.aspfree.com/showthread.php?t=26973

Bill Schroyer
[email protected]
http://www.frontpagewiz.com

-----Original Message-----
Hello, I have a database which has a query with a string
like Sum([person])/count(*)*100. When I go to display the
results of the query on my page it lools like this <%=rs
("person")%>% the only problem I am having is that when it
is not an even number of votes I get a really long decimal
number. Is there a simple way in asp to make the results
round to 1 decimal place or just cut it off after a
certain number of digits or is this a strictly MS Access
thing. Either way thanks for your help. Matt
 
M

Matthew

Sorry if this is stupid but I am not familiar with how to implement that function into the asp code to work. Also on teh page link above this code was given for formatting numbers to 2 decimal places variable = formatnumber(variable,2
is there something wrong with this code its seems easier to use and implement. Although it might not add the flexibility but it should do for me. Thanks Matthew
 
T

Thomas A. Rowe

Try

<%=rs("person")%>

change to

<%=FormatNumber(rs("person"),0)%>%

--
==============================================
Thomas A. Rowe (Microsoft MVP - FrontPage)
WEBMASTER Resources(tm)

FrontPage Resources, WebCircle, MS KB Quick Links, etc.
==============================================


Matthew said:
Hello, I have a database which has a query with a string like Sum([person])/count(*)*100. When I
go to display the results of the query on my page it lools like this <%=rs("person")%>% the only
problem I am having is that when it is not an even number of votes I get a really long decimal
number. Is there a simple way in asp to make the results round to 1 decimal place or just cut it off
after a certain number of digits or is this a strictly MS Access thing. Either way thanks for your
help. Matt
 
Top