Skip to main content
4 of 5
Added a db<>fiddle. Rephrased som excerpts.
MDCCL
  • 8.5k
  • 3
  • 31
  • 62

Two conversions of practically the same number giving two different results

To my surprise, I run the following queries in SQL Server 2014 and each returns a different result, as shown in this db<>fiddle...

This

Select convert(numeric(19,2),convert(float,9.76499999999999999999999999))

gives 9.76.

And this

Select convert(numeric(19,2),convert(float,9.7649999999999999999999))

gives 9.77.

Can someone explain why one truncates while the other rounds up? This is causing a nightmare for me.

JohnG
  • 1.1k
  • 2
  • 11
  • 27