Click to See Complete Forum and Search --> : math


Dingojoe
June 2nd, 1999, 09:54 PM
lets say i have a text box that contains

123223423.23423234

is there a way to assign a variable (lets say A) to be a rounded up # of the textbox?

basically..how do i get rid of the "." and just store the rounded up #

?

Ravi Kiran
June 3rd, 1999, 02:58 AM
Hi,

If you are within the range of 'Long' (2,147,483,647) you can use
CLng(Text1.text) to convert the text to long and this conv. is "rounded to nearest whole no (sign incl)".

If you are outside that range, no equil for int64 in VB ( 5.0 atleast, i dont know abt 6.0).
So you have to go for Decimal/Currency which have limited no. of decimal pts. above them you have to go for Single/Double. For display, make good use for Format fn, so that for all 'practical purposes' it looks like a long-long int:-)

Or if you have the courage, go down to CRT functions ( 'C'-Runtime & WinAPI) that support int64.

Ravi

Dingojoe
June 3rd, 1999, 03:51 PM
unfortunately, that doesnt answer my question just yet :) ..u took is far beyond what i needed

basically i have a text1.text containing the intergers 12345.1234

since 12345 rounded up or down is still 12345 then that what i want to return as the value

i think i thas something to do with absolute value..

eg.. abs(text1.text)

but for some reaosn i cant get it to work?

-joe

?

Dingojoe
June 3rd, 1999, 06:43 PM
ennvermind :) thanks anyways
i got it

int(text1.text)

=)>

?

Ravi Kiran
June 4th, 1999, 02:07 AM
Mind you, i used the phrase - "rounded to nearest whole no (sign incl)".

If you come from 'C' bkgrnd there are 'floor' and 'ceil' functions. 'Int' in Vb is similar to 'floor'.

So, int(123.123) = int(123.523) = 123 i.e it always removes the fractional part and gives
the whole no.
while cint(123.123) = 123 and cint(123.523) = 124 and also CInt(123.5000) = 124.

For negetive nos int() gives lot of trouble.
int(-123.1) gives -124 and not -123 as we normally expect.!!, while Cint gives -123

Hence Rounding Up or down is not same as rounding to nearest integer!!

Ravi

Brian
June 4th, 1999, 05:52 AM
CInt also has some "unexpected" behaviour:

CInt(2.5) = 2
CInt(1.5) = 2

Int(2.5) = 2
Int(1.5) = 1

I'm told that this behaviour is documented, but that doesn't make it "expected".

Dingojoe
June 4th, 1999, 08:56 PM
yeah i foudn i had the same problem.. but i managed to fix it :)

thanks again tho

?

Ravi Kiran
June 7th, 1999, 03:05 AM
Use this, to get the nearest-integer always:

int(val + 0.5)