Dividing variables and rounding

N

nathan

Hey folks, I'm doing up a stats page for a survey, and this is a small
part of one of the results. Below is part of the code to do
totals/percents. My question is, how do i make it so myAnswer is
written with two decimal places?

Currently, it displays the percent as 4.76190476190476

<%
myAnswer = OneAgree_total / OneTotal_total * 100
Response.Write "" & myAnswer
%>

Thanks folks.
 
H

Harag

Look up the "FormatNumber" function

myAnswer = FormatNumber(OneAgree_total / OneTotal_total * 100 ,2)

or you could *100 then make it an integer/long then devide by 100

eg:

My answer = clng((oneAgree_Total/ OneTotal_total)*100) / 100



HTH.
Al.
 
D

dlbjr

<SCRIPT language="vbscript" runat="server">
'Place these function in an include
'file to use on all pages

'Validate a Number
function CheckNumber(strData)
strData = Trim(strData)
If IsNUmeric(strData) Then
CheckNumber = strData
Else
CheckNumber = 0
End If
End Function

'Trap Divide By 0 Errors
function Divide(strNom,strDeNom)
strNom = CheckNumber(strNom)
strDeNom = CheckNumber(strDeNom)
If CDbl(strNom) > 0 And CDbl(strDeNom) > 0 Then
Divide = strNom / strDeNom
Else
Divide = 0
End If
End Function
</SCRIPT>


<%
'Here is the asp code
myAnswer = FormatNumber(Divide(OneAgree_total,OneTotal_total) * 100,2)
Response.Write myAnswer
%>


-dlbjr

Discerning resolutions for the alms
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,142
Messages
2,570,819
Members
47,367
Latest member
mahdiharooniir

Latest Threads

Top