Qbasicnews.com

Full Version: Long, Double and Single
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
How do i input a large number in a data file

What i mean is do i use Long, Single or Double(or anything else) to enter data in to a file

the number is 7000000
Hi Champions_2002,

If you're always sure your large number will never have decimals, you can use LONG as it can take 2^31 (2,000,000,000) some values.

But if it might need decimals, DOUBLE would take the largest values.
Quote:How do i input a large number in a data file

What i mean is do i use Long, Single or Double(or anything else) to enter data in to a file

the number is 7000000
The data type LONG can hold a number up to between -2,147,483,648 and 2,147,483,647 (&h80000000 to &hFFFFFFFF for negative numbers and &h0 to &h7FFFFFFF for positive numbers, including 0 in this case).

Your number is only 7,000,000. LONG should be enough unless it happens to increase beyond 2,147,483,647, which means DOUBLE would be better. The problem with SINGLE and DOUBLE is the fact that they deal with decimals and some precision will be lost. It usually isn't a big problem, but occasionally, you'll wonder why some mathematical calculations result in an answer like .249999999999213. This is because of floating-point rounding error.
You should probably prefer using LONG data types for portability reasons. If you need to use floating point numbers, I'd recommend storing the number as a string, or use your own format.

That said, there's absolutely no reason to use floating point numbers to represent integers above the limits of a LONG. Make your own 64-bit integer type if you need bigger integers. Do a search on MSDN for LARGE_INTEGER
thats a good idea! never thought of converting it to a string!
Watch out when converting floating point numbers to a string. The number may have bunch of values after the decimal point and you'll end up with a very long string.
*****
I'm not sure how much value this would have here, but I made a solar system simulation in QB, a few years back, and the far planets/comets were very unstable using single precision floats. I mean, if you were close to them, they would *jump* like 50 pixels at a time across the screen. Usng double helped quite a bit though. Wink
Quote:Watch out when converting floating point numbers to a string. The number may have bunch of values after the decimal point and you'll end up with a very long string.
i am believing that that problem could be elude by using the functions MKL$, MKS$, MKD$. that way a long or single number could be converted to a Four bytes string; double numbers could be converted to an Eight bytes string.
BIGINT anyone?

Actually I already did some functions for BIGDEC in FB ^^

Anonymous

Quote:
Moneo Wrote:Watch out when converting floating point numbers to a string. The number may have bunch of values after the decimal point and you'll end up with a very long string.
i am believing that that problem could be elude by using the functions MKL$, MKS$, MKD$. that way a long or single number could be converted to a Four bytes string; double numbers could be converted to an Eight bytes string.


yeah, but you can't just print that string, the 'chars' in that string contain the actual byte data of those numbers. its not the same thing.
Pages: 1 2