# Qbasicnews.com

Full Version: Rounding numbers larger than 32k
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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.

*****
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.
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.
*****
It does return an integer, but a mathematical integer. That is, a whole number.

Silly MS QB help.
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.
*****