tsql casting to money rounds up

别等时光非礼了梦想. 提交于 2019-12-11 00:48:52

问题


When casting a varchar value to MONEY it is rounding the value to the nearest 0.10, how do I prevent this rounding up?

UPDATE: I found the problem. In a subquery, the value is being CAST from varchar to FLOAT and then I was trying to CAST from FLOAT to MONEY.


回答1:


I am not sure i understand your problem.

When looking at the code below

DECLARE @money AS MONEY,
        @varchar AS VARCHAR(20)

SET @varchar = '1000.456789'

SELECT CAST(@varchar AS MONEY)
SELECT @money = @varchar
SELECT @money

it gets rounded to the nearest 4th decimal, not the 1st decimal.




回答2:


See this very interesting blog post by Brad Schulz on that exact topic:

Throw Your MONEY Away

He advocates never even using the MONEY datatype for various reasons - interesting and thought inspiring read!

Marc



来源:https://stackoverflow.com/questions/1720454/tsql-casting-to-money-rounds-up

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