Wrox Programmer Forums
|
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
 
Old August 19th, 2003, 10:15 AM
Authorized User
 
Join Date: Aug 2003
Posts: 83
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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
 
Old August 19th, 2003, 10:37 AM
Authorized User
 
Join Date: Jun 2003
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to sidneyfuerte Send a message via AIM to sidneyfuerte Send a message via MSN to sidneyfuerte Send a message via Yahoo to sidneyfuerte
Default

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
 
Old August 19th, 2003, 10:46 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 141
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Code:
Round(4.5,0)
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
 
Old August 19th, 2003, 03:10 PM
Authorized User
 
Join Date: Aug 2003
Posts: 83
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

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.
 
Old August 19th, 2003, 03:23 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 141
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
 
Old August 20th, 2003, 02:55 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

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
 
Old August 20th, 2003, 03:09 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 596
Thanks: 1
Thanked 3 Times in 3 Posts
Default

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.
======================================





Similar Threads
Thread Thread Starter Forum Replies Last Post
CInt versus Integer.Parse - what's the difference? sektor Visual Basic 2005 Basics 2 June 5th, 2008 04:23 AM
Whats the work around? aaronmuslim XSLT 5 March 26th, 2008 04:10 PM
cdbl or cint crmpicco Classic ASP Basics 2 November 9th, 2005 11:49 AM
Whats the diff?? nsakic XSLT 2 January 17th, 2004 07:11 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.