Question: Cast decimal real to double precision produces strange behavior

Question

Cast decimal real to double precision produces strange behavior

Answers 1
Added at 2016-11-25 16:11
Tags
Question

I'm trying to cast a decimal real to double precision and it has the following behavior:

select 2.2::real::double precision;

Outputs:

2.20000004768372 (double precision)

How can I make it output the following:

2.2 (double precision)

Thank you

Answers to

Cast decimal real to double precision produces strange behavior

nr: #1 dodano: 2016-11-25 16:11

Thank you a_horse_with_no_name, nice reading.

I solved my problem by casting to text before converting to double:

select 2.2::real::text::double precision;

That outputs:

2.2 (double precision)

And for future reference, if you must use double precision, you shouldn't mix it with real.

Source Show
◀ Wstecz