Jerry M Sunny
Jerry M Sunny

Reputation: 23

Float operation gives wrong result in Postgres

When running the below code

select 5259.56::FLOAT8=(1800.12::FLOAT8+3459.44::FLOAT8)

has output as false but when I run

select 5259.55::FLOAT8=(1800.11::FLOAT8+3459.44::FLOAT8)

It gives true as output. Any possible explanation will be greatly appreciated.

Upvotes: 1

Views: 938

Answers (1)

S-Man
S-Man

Reputation: 23686

This is caused by the floating point arithmetics. (check the link @a_horse_with_no_name provided in the comments)

To fix it and if you really need it: Type numeric can do exact calculations. float not.

https://www.postgresql.org/docs/current/static/datatype-numeric.html

Upvotes: 3

Related Questions