docs icon indicating copy to clipboard operation
docs copied to clipboard

Document FLOAT -> INT casting behavior

Open mgartner opened this issue 1 year ago • 0 comments

Marcus Gartner (mgartner) commented:

We recently fixed an incompatibility with Postgres with the behavior of casting a FLOAT to an INT. The fix will be included in v24.1. See https://github.com/cockroachdb/cockroach/pull/117798.

We should document the behavior of these casts. Specifically, a FLOAT to INT cast rounds the float to the nearest integer. If it is equidistant to two integers, it is rounded to the even integer. For example:

SELECT f::INT FROM (VALUES (-1.5::FLOAT), (-0.5::FLOAT), (0.5::FLOAT), (1.5::FLOAT)) v(f);
--  f
-- ----
--  -2
--   0
--   0
--   2
-- (4 rows)

Jira Issue: DOC-9622

mgartner avatar Feb 02 '24 18:02 mgartner