CS FundamentalsModerateTCS NQT · Infosys pattern

A column `price NUMERIC` (arbitrary precision decimal) is compared against a literal using `price = 19.99`. Why is this generally SAFE from the classic floating-point equality problem that `price = 19.99` would risk if price were a `FLOAT`/`DOUBLE` column instead?

  1. A. NUMERIC and FLOAT behave identically in every database
  2. B. NUMERIC/DECIMAL types store an exact base-10 representation (not a binary floating-point approximation), so a value like 19.99 is stored exactly, unlike FLOAT/DOUBLE, which can only approximate most decimal fractions in binary, making equality comparisons on them unreliable
  3. C. FLOAT columns cannot be compared with = at all
  4. D. NUMERIC columns automatically round to the nearest cent

Correct answer: B. NUMERIC/DECIMAL types store an exact base-10 representation (not a binary floating-point approximation), so a value like 19.99 is stored exactly, unlike FLOAT/DOUBLE, which can only approximate most decimal fractions in binary, making equality comparisons on them unreliable

IEEE floating-point (FLOAT/DOUBLE) represents numbers in binary, and many ordinary decimal fractions (like 0.1 or 19.99) have no exact finite binary representation, leading to tiny rounding errors that break naive equality checks. NUMERIC/DECIMAL types are defined to store an exact decimal value (often as scaled integers internally), so a stored 19.99 really is exactly 19.99, and comparing it for equality against the literal 19.99 is reliable.

More DBMS and SQL questions

Exams that ask this topic