Ask a Question related to ASP, Design and Development.
-
Adam Knight #1
Rounder A Number Up!!
I am dividing a value by two..what i need is to round the number up if it is
not a whole number.
Any suggestions on how to do this ??
Help appreciated!!
AK
Adam Knight Guest
-
int Number to text Number Function / UDF ?
Is there a function that converts e.g. 3 to Three? Probably not but I just thought I'd ask. -
Number to hex ?
Looking at a few scripts, too disguise ID numbers or make them random, there appears to be a conversion to an alphanumeric number. e.g.... -
sort from the smallest number to the highest number
Hi Just say I want to sort the row by using the fifth column data as reference from the smallest the largest number, if using sort, It will give... -
sh: bad number
Hi, I compiled a simple program with perl. But I ran into some problems. sh: campusUnderAttack.out: bad number I try to execute a program and... -
tty-dev-number <-> /dev/pts
Hi, I'm writing a program under Solaris (sparc) that has to know from what machine a user is logged on who is starting that program. Reading... -
Ken Schaefer #2
Re: Rounder A Number Up!!
See if the number is not an integer, and if so, convert it to an integer and
add one.
Cheers
Ken
"Adam Knight" <aj.knight@optusnet.com.au> wrote in message
news:%231IM5OoeDHA.3228@tk2msftngp13.phx.gbl...
: I am dividing a value by two..what i need is to round the number up if it
is
: not a whole number.
:
: Any suggestions on how to do this ??
:
: Help appreciated!!
:
: AK
:
:
Ken Schaefer Guest
-
bart plessers #3
Re: Rounder A Number Up!!
Cint(number+0.5)
or
Cint(number) + 1
--
==========================================
Hyper A.R.T.
bart plessers
Paul Van Ostaijenlaan 4
3001 Heverlee
BELGIUM
tel: +32 (16) 23.40.85
fax: +32 (16) 23.41.06
==========================================
"Adam Knight" <aj.knight@optusnet.com.au> wrote in message
news:#1IM5OoeDHA.3228@tk2msftngp13.phx.gbl...is> I am dividing a value by two..what i need is to round the number up if it> not a whole number.
>
> Any suggestions on how to do this ??
>
> Help appreciated!!
>
> AK
>
>
bart plessers Guest
-
ljb #4
Re: Rounder A Number Up!!
sounds like a ceiling function
[url]http://www.vb2themax.com/Item.asp?PageID=CodeBank&Cat=110&ID=24[/url]
vb2themax has the code
Function Ceiling(Number)
Ceiling = -Int(-Number)
End Function
"Adam Knight" <aj.knight@optusnet.com.au> wrote in message
news:#1IM5OoeDHA.3228@tk2msftngp13.phx.gbl...is> I am dividing a value by two..what i need is to round the number up if it> not a whole number.
>
> Any suggestions on how to do this ??
>
> Help appreciated!!
>
> AK
>
>
ljb Guest
-
Andrew J Durstewitz #5
Re: Rounder A Number Up!!
Actually, I just dealt with this...
intScreens = (cnItems.RecordCount Mod 15) + Int(cnItems.RecordCount /
15)
MOD will return a zero if there is no remainder and a one if there is.
Int forces the number to be a whole number, therefore getting ride of
everything past the decimal.
I'm sure you can figure out how to apply this to what you need to do.
hth,
Andrew
DEVBuilder.org, [url]http://www.DEVBuilder.org[/url]
ASP,ASP.NET,VB.NET,PHP,Java,and SQL Support, all in one place.
Andrew J Durstewitz Guest
-
Dan Brussee #6
Re: Rounder A Number Up!!
On 15 Sep 2003 15:56:14 GMT, Andrew J Durstewitz
<adurstew@devbuilder.org> wrote:
MOD does not return zero or one. The MOD operator returns the>Actually, I just dealt with this...
>
>intScreens = (cnItems.RecordCount Mod 15) + Int(cnItems.RecordCount /
>15)
>
>MOD will return a zero if there is no remainder and a one if there is.
>Int forces the number to be a whole number, therefore getting ride of
>everything past the decimal.
>
>I'm sure you can figure out how to apply this to what you need to do.
>
remainder after division. It can be a very helpful operator in certain
cases.
A typical case where I have used it is to cycle through a number of
items, once per day. I take a date, do some date math to determine the
number of days since that date till now, then use MOD to figure out
which item to display...
s(0) = "First Item"
s(1) = "Second Item"
s(2) = "Third Item"
s(3) = "Fourth Item"
s(4) = "Fifth Item"
itm = s(datediff("d", "9/11/2001", now) mod 5)
After dividing the number of days since 9/11, the MOD operator returns
the remainder. Let's say there were only 2 days since 9/11. 2 MOD 5
returns 2, so the s(2) would be returned. On the third day 3 MOD 5
returns 3, so s(3) would be returned.
Later, when it's 303 days after 9/11, 303 MOD 5 returns 3 (303 divided
by 5 is 60 with a remainder of 3).
Dan Brussee Guest
-
Andrew J Durstewitz #7
Re: Rounder A Number Up!!
My bad, I mis-stated what I was trying to say. Your correct.
However, if you use the MOD the poster will be able to round up.
Basically if the MOD return is greater than 1 it's not a whole number.
Turn it into an integer and add 1. Now it's the next higher number and
whole.
Andrew
DEVBuilder.org, [url]http://www.DEVBuilder.org[/url]
ASP,ASP.NET,VB.NET,PHP,Java,and SQL Support, all in one place.
Andrew J Durstewitz Guest
-
Dan Brussee #8
Re: Rounder A Number Up!!
On 15 Sep 2003 17:26:15 GMT, Andrew J Durstewitz
<adurstew@devbuilder.org> wrote:
Dont mean to harp on it, but how would MOD tell you if it's a whole>My bad, I mis-stated what I was trying to say. Your correct.
>
>However, if you use the MOD the poster will be able to round up.
>Basically if the MOD return is greater than 1 it's not a whole number.
>Turn it into an integer and add 1. Now it's the next higher number and
>whole.
>
number? It's really meant to be used with integers
17 MOD 5 returns 2
All numbers are whole.
Dan Brussee Guest
-
Dave Anderson #9
Re: Rounder A Number Up!!
"Adam Knight" wrote:
Whatever you do, avoid CInt. Here's why (see the section on Bankers>
> I am dividing a value by two..what i need is to round the
> number up if it is not a whole number.
Rounding)...
[url]http://support.microsoft.com/default.aspx?scid=kb;EN-US;q196652[/url]
....as well as the [Note] here:
[url]http://msdn.microsoft.com/library/en-us/script56/html/vsfctCInt.asp[/url]
In short, here's a decent VBScript implementation of a "ceiling" function:
Function RoundUp(val)
RoundUp = Int(val) + Sgn(val - Int(val))
End Function
Just in case you care about negative numbers, consider what behavior you
want for negative values before implementing this. "Rounding up" means
that -1.2 rounds to -1. If you prefer that -1.2 round to -2, use something
like this:
Function RoundUp(val)
RoundUp = Fix(val) + Sgn(val - Fix(val))
End Function
JScript is simpler, in a way. The first example above is merely:
Math.ceil(val)
The second is a bit trickier. Here are two implementations:
1. val/Math.abs(val) * Math.ceil(Math.abs(val))
2. val > 0 ? Math.ceil(val) : Math.floor(val)
Enjoy exploring this.
--
Dave Anderson
Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms. Please do not contact
me directly or ask me to contact you directly for assistance. If your
question is worth asking, it's worth posting.
Dave Anderson Guest
-
Dave Anderson #10
Re: Rounder A Number Up!!
"Dan Brussee" wrote:
"The modulus, or remainder, operator divides number1 by number2 (rounding>
> Dont mean to harp on it, but how would MOD tell you if it's
> a whole number? It's really meant to be used with integers
floating-point numbers to integers) and returns only the remainder as
result."
[url]http://msdn.microsoft.com/library/en-us/script56/html/vsoprmod.asp[/url]
*** HOWEVER ***
Mod uses Banker's Rounding, so it should be avoided at all costs:
1.5 Mod 10 is 2
2.5 Mod 10 is 2
--
Dave Anderson
Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms. Please do not contact
me directly or ask me to contact you directly for assistance. If your
question is worth asking, it's worth posting.
Dave Anderson Guest



Reply With Quote

