How can the following result of casting from float to numeric be explained?

瘦欲@ 提交于 2019-12-11 09:43:17

问题


DECLARE @f AS FLOAT = '29545428.022495';
SELECT CAST(@f AS NUMERIC(28, 14)) AS value;

29545428.02249500200000

Today I've read this example. I understand the problem of floating point numbers but do not understand the result of this casting. How it works?

UPDATE

First, we can replace varchar in the first line, the result will be the same.

DECLARE @f AS FLOAT = 29545428.022495;

Second, I think the problem is in casting. Try the following code.

DECLARE @f AS FLOAT = 29545428.022495;
select @f - 29545428;

0,0224950015544891

Maybe it is the reason of 002 in the end. It works with other numbers.

UPDATE 2

OK, I think I understand it in a wrong way. Here's a related question and the answer.

来源:https://stackoverflow.com/questions/34316871/how-can-the-following-result-of-casting-from-float-to-numeric-be-explained

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!