Qbasicnews.com
Rounding numbers larger than 32k - Printable Version

+- Qbasicnews.com (http://qbasicnews.com/newforum)
+-- Forum: QbasicNews.Com (http://qbasicnews.com/newforum/forum-3.html)
+--- Forum: Challenges (http://qbasicnews.com/newforum/forum-10.html)
+--- Thread: Rounding numbers larger than 32k (/thread-5689.html)



Rounding numbers larger than 32k - Moneo - 01-15-2005

Rounding algorithms generally use the INT function which will not handle numbers greater than 32k.

CHALLENGE:
Write a subroutine, function or sub-program that can correctly round positive or negative numbers using the "conventional rounding method", which is: add .5 and truncate.

Input is a double precision number, which can be signed.
Output is also a double precision number,which is a whole number that can be signed.

Please test your entries.
*****


Re: Rounding numbers larger than 32k - Sterling Christensen - 01-15-2005

Code:
n# = 100000000.9#
n# = INT(n# + .5)
print n#
The result in this example is 100000001, which is too large for a LONG. Proof positive that INT returns a double, thus fitting all the requirements for the challenge 8). Yes, I'm a lazy cheater :lol:. No doubt there's a more interesting way to do it.


Rounding numbers larger than 32k - Moneo - 01-16-2005

Sterling,

You're absolutely rignt. I tested it with up to 11 digit whole numbers with decimals, positive and negative, and it accepts them.

Where did I get the idea that INT could not handle numbers larger than the integer limit of 32k? I checked my manual, which is QuickBasic 4.0, although I'm running 4.5, and it says that it returns AN INTEGER. I even had underlined the word INTEGER. Maybe 4.0 had that restriction. Who knows?

In any event, SORRY GUYS FOR THE BOGUS CHALLENGE INFORMATION.
*****


Rounding numbers larger than 32k - Z!re - 01-16-2005

It does return an integer, but a mathematical integer. That is, a whole number.

Silly MS QB help.


Rounding numbers larger than 32k - Moneo - 01-24-2005

I finally discovered where I saw the limit of 32k, It's in the CINT function, not the INT. I never use CINT 'cause it gives some weird results for certain negative numbers.
*****