 |
| Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0 |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

August 19th, 2003, 10:15 AM
|
|
Authorized User
|
|
Join Date: Aug 2003
Posts: 83
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
whats up with round() and cint() returning even
Is there a round function that will round 4.5 to 5? Seems we have CInt() which returns even numbers only as well as Round() which also returns even numbers. I'm in desperate need of a function that returns the next higher value if argument is n.5 even if return value is odd. Thanks
|
|

August 19th, 2003, 10:37 AM
|
|
Authorized User
|
|
Join Date: Jun 2003
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
What i usually do is i just create my own function. I dont know if there's a built-in function for this kind of problem, but incase somebody know's post it here as well :)
Anyways a sample code of what i do to this:
Dim sTemp
Dim nDbl
sTemp = "4.0"
decval = Mid(sTemp, InStr(1, sTemp, ".") + 1)
Whole = CDbl(sTemp)
If decval >= 5 Then
Whole = CInt(sTemp)
Whole = Whole + 1
End If
Hope this helps.
Thanks/Regards
Sidney
|
|

August 19th, 2003, 10:46 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 141
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
should = 5
Code:
formatnumber(4.5,0)
should = 4
formatnumber just truncates where round actually rounds. Did you put in the second parameter of 0 so it rounded to a whole number.
Chris
|
|

August 19th, 2003, 03:10 PM
|
|
Authorized User
|
|
Join Date: Aug 2003
Posts: 83
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Give it a whirl my friend and see for yourself.
|
|

August 19th, 2003, 03:14 PM
|
|
Authorized User
|
|
Join Date: Aug 2003
Posts: 83
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thank you Sidney, your code is what I need, if I wasn't so confident that Microsoft's code was flawless I'd say Round() has a bug.
|
|

August 19th, 2003, 03:23 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 141
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
It appears the functions are switched. You can use the formatnumber function to give you what you need without having to reinvent the wheel on your own.
Chris
|
|

August 20th, 2003, 02:55 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Its a strange one - Round() should round up, but as lcsgeek says, Round(4.5, 0) => 4. Maybe its just the old problem of not being able to represent decimals perfectly in binary, because Round(4.5000001, 0) => 5  
|
|

August 20th, 2003, 03:09 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 596
Thanks: 1
Thanked 3 Times in 3 Posts
|
|
This is being discussed in another topic now.
I always thought you must round to the even and was very confused by everyones confusion.
I thought 4.5 to 4, 5.5 to 6 is correct but there appears to be two schools of thought.
Check out:
http://p2p.wrox.com/topic.asp?TOPIC_ID=3122
http://www.xbeat.net/vbspeed/i_BankersRounding.htm
======================================
They say, best men are moulded out of faults,
And, for the most, become much more the better
For being a little bad.
======================================
|
|
 |