Real vs. Floating Point vs. Money

前端 未结 4 1146
走了就别回头了
走了就别回头了 2020-11-27 06:30

Why when I save a value of say 40.54 in SQL Server to a column of type Real does it return to me a value that is more like 40.53999878999 instead of 40.54? I\'ve seen this

4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-27 07:22

    In a nutshell, it's for pretty much the same reason that one-third cannot be exactly expressed in decimal. Have a look at David Goldberg's classic paper "What Every Computer Scientist Should Know About Floating-Point Arithmetic" for details.

提交回复
热议问题