Rounding is part of the nature of floating point. Also, remember that the numeric data types are binary, not decimal.

If you want to use floating point numbers, and avoid rounding, you must:

**Use a data type with sufficient precision. Avoid fractions whose denominators are not powers of 2.**For details of data type precision, see:

http://en.wikipedia.org/wiki/IEEE_754-1985

http://en.wikipedia.org/wiki/Extended_precision#x86_Extended_Precision_Format

In this case, 6789 / 10000:

6789 has prime factors 3, 31 and 73.

10000 has prime factors 2 and 5.

The fraction cannot be reduced so that the denominator would be a power of 2. Therefore 6789 / 10000

**cannot** be stored accurately in a binary floating point number of

**any precision**.

Why does 1 / 3 repeat in decimal? Because the denominator has a prime factor (3) other than 2 or 5. To terminate in base 10, the reduced fraction must not have a denominator other than 2 or 5.

750 / 1000 terminates in both binary and decimal.

The reduced fraction is 3 / 4.

4 has a prime factor of 2. It does not have a prime factor other than 2, so it terminates in binary. It does not have a prime factor other than 2 or 5, so it terminates in decimal.

What can you do? Use an integer. 123456789012346789 fits in an _INTEGER64. You will not have any rounding with integers, but you can still have overflow problems. You could implement your own fixed point binary or decimal math operations, or use the existing operations, compensating where necessary. If you do a search, you should find related discussion on this subforum related to Visual BASIC's CURRENCY type.

http://www.qb64.net/forum/index.php?topic=5092.0http://www.qb64.net/forum/index.php?topic=1551.0Examples of favoring integers over fractions would include using integer pennies instead of fractional dollars, and using integer milliseconds instead of fractional seconds.

Regards,

Michael