How do I round a double precision to a whole number

By: Borland Staff

Abstract: The best way to round a double precision number is to write a UDF to do the rounding

Problem:
Can't round a double precision number to a whole number

Solution:
The information in this article applies to:
  * InterBase v4.x
  * InterBase v5.x

The best way to round a double precision number is to write
a UDF to do the rounding.  InterBase does not have any internal
rounding functionality.

An alternative would be to cast the double to an integer.  This
will work as long as the result will fit in the 32-bit integer
field.  This is not the favorable method, however, because the 64-bit
double precision fields can hold significantly larger numbers than
the integer field can.  If the rounded number does NOT fit into a 32-bit
integer, an arithmetic overflow error will be produced.

Server Response from: ETNASC04