Subject Re: [firebird-support] Double precision field problem
Author Svein Erling Tysvaer
Whether you change the values manually or not doesn't matter, double
precision is a floating data type and many values cannot be stored
exactly with such a datatype.

The square root of 2 is an exact value, but it cannot be written exactly
in a decimal system, whereas the square root of 4 can do so without
problems. Similarly (I think), many decimal values cannot be written
exactly when using a double precision data type.

I don't know whether 79.69, 78.12 or 1.57 can be stored exactly as
double precision, but I do know that if you want to operate with exact
values then you simply cannot use double precision. Firebird has some
datatypes that are appropriate for exact representation of numbers and
some that aren't and both DECIMAL and NUMERIC are able to store 79.69,
78.12 and 1.57 as exact values.

HTH,
Set

ibrahim bulut wrote:
> This problem does not happen all the records
> Generally records are ok, but some records have problem
>
> When i change the field's value manuel (with ibconsole)
> Problem still occurs
>
> Field1's value is exactly 79.69 and
> Field2's value is exactly 78.12
>
> because i have changed them manually
>
> but result is not exact value
>
> _____
>
> From: firebird-support@yahoogroups.com
> [mailto:firebird-support@yahoogroups.com] On Behalf Of Svein Erling Tysvaer
> Sent: Monday, October 30, 2006 2:51 PM
> To: Firebird-support
> Subject: Re: [firebird-support] Double precision field problem
>
>
>
> You get what you ask for, Ibrahim. Floating point numbers (e.g. double
> precision) are good for measuring things, it doesn't matter whether the
> length of a line is 1.57 metres or 1.5699999999999 metres. Field1
> doesn't have the exact value 79.69, it has a value of approximately
> 79.69 (e.g. 79.69000000000000001238) and similar for Field2.
>
> If such differences do matter, you should probably use fixed point
> numbers - e.g. decimal or numeric.
>
> HTH,
> Set
>
> ibrahim bulut wrote:
>> i am in trouble double precision field with subtract operation
>>
>> field1 is double precision
>> field2 is double precision
>>
>> field1's value is 79.69
>> field2's value is 78.12
>>
>> when i subtract field2 from field1 with this sql statement
>>
>> select field1 - field2 from table1
>>
>> the result is 1,56999999999999
>>
>> the result must be 1,57
>>
>> what is the problem
>>
>> ibrahim bulut
>> software and database expert
>> iletisim online ltd.sti.
>> turkish republic