Inaccurate fractions.

By: Ben Matterson

Abstract: A brief description why fractional numbers retrieved from InterBase may differ from the number stored.


When I stored floating point numbers sometimes I get back a number that is not quite the same as what I stored. Why?


This happens due to the way decimal numbers are represented inside the computer. The fractional part of the number cannnot be stored exactly unless the fraction is an exact power of two, such as one half, one fourth, one eight, etc. If your data has fixed number of places after the decimal point, and you are using a dialect 3 database, you can work around this limitation by using a NUMERIC datatype, in which InterBase stores the decimal as an integer, and keeps track of where the decimal point goes.

For more information on binary storage of decimal numbers see the InterBase Knowledgebase article Accuracy of the NUMERIC and DECIMAL data types.

For more information on the InterBase NUMERIC datatype please see the "InterBase Data Definition Guide", chapter 4, "Specifying Datatypes".

Server Response from: ETNASC04