我无法使用CAST或CONVERT将varchar转换为小数。当我检查字符串是否为有效数字时,ISNUMERIC返回为有效数字。但是,当使用CAST或CONVERT时,会抛出“将数据类型varchar转换为数字时出错”。
尝试了不同的选择,但没有运气。如果我从字符串中删除“ e +”,它可以工作,但结果不正确。
我尝试使用REPLACE查看是否有任何东西。但是没用。
select isnumeric( '1.67022e+006') as c,
CAST('1.67022e+006') AS DECIMAL(24, 10)) AS ci,
CAST(replace('1.67022e+006','','') AS DECIMAL(24, 10)) AS cii,
CAST(replace('1.67022e+006','e+','') AS DECIMAL(24, 10)) AS civ,
CAST(1.67022e+006 AS DECIMAL(24, 10)) AS ciii;
CAST('1.67022e+006') AS DECIMAL(24, 10)) --> Error
CAST(replace('1.67022e+006','','') AS DECIMAL(24, 10)) --> error
CAST(replace('1.67022e+006','e+','') AS DECIMAL(24, 10)) --> 1.6702200600
CAST(1.67022e+006 AS DECIMAL(24, 10)) --> 1670220.0000000000
答案 0 :(得分:0)
我认为您不能直接将CAST
的指数数字decimal
CAST()
到FLOAT
,然后到DECIMAL
select CAST(CAST('1.67022e+006' AS FLOAT) AS DECIMAL(24, 10))