Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

round method 2

Status
Not open for further replies.

920506

Programmer
Jun 13, 2003
201
US
Hi all,
I was confused by using round method.

The following statements:
Response.Write Round(61.865, 2) & "<br>"
Response.Write Round(61.855, 2) & "<br>"
Response.Write Round(61.845, 2) & "<br>"
Response.Write Round(61.835, 2) & "<br>"
give me the following data:
61.86
61.86
61.84
61.84
But what I am expecting is
61.87
61.86
61.85
61.84
what is the problem? is there any other method round to two decimal with way I wanted?
Thank you.
Betty
 
try this:
Code:
Function RoundUp(num1)
RoundUp = 0
If IsNumeric(num1) Then
RoundUp = FormatNumber(CDbl(num1) + .5,0)
End If
End Function

then you can call it as follows...

Response.Write RoundUp(61.865) & "<br>"
Response.Write RoundUp(61.855) & "<br>"
Response.Write RoundUp(61.845) & "<br>"
Response.Write RoundUp(61.835) & "<br>"

-DNG
 
tru this:

<%

Response.Write FormatNumber(61.865,2) & "<br>"
Response.Write FormatNumber(61.855,2) & "<br>"
Response.Write FormatNumber(61.845,2) & "<br>"
Response.Write FormatNumber(61.835,2) & "<br>"


%>

-DNG
 
Yep. FormatNumber. I was just playing around a little. take a look at this.

Code:
<table>
    <tr>
        <th>Original</th>
        <th>Round</th>
        <th>FormatNumber</th>
    </tr>
    <%
    For i = -20.5 To 20.5
        Response.Write("<tr><td>" & i & "</td><td>" & Round(i, 0) & "</td><td>" & FormatNumber(i, "0") & "</td></tr>")
    Next

    %>

</table>

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Hi all,
Thanks for all your response. Very informational and very interesting.
That's help a lot.
I read the article provided by George. I just never knew bankers rounding before reading this article.

Sincerely
Betty
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top