如果是2005以上版本,直接:
selectltrim(cast(col asfloat)) from tb
例如:
DECLARE @lastprice_new VARCHAR(50)
SELECT @lastprice_new=ltrim(cast((16955.20) as float))
PRINT @lastprice_new
打印出来:16955.2
例如:
DECLARE @str_md5 VARCHAR(32)
DECLARE @id VARCHAR(50)
DECLARE @lastprice_new VARCHAR(50)
SELECT @id=id ,@lastprice_new=ltrim(cast((price-@price) as float)) FROM dbo.tbl_protect WHERE joinno=@joinno
SELECT @id=id ,@lastprice_new=ltrim(cast((price-@price) as MONEY)) FROM dbo.tbl_protect WHERE joinno=@joinno
取小数点两位
select cast(round(1.00/3,2) as decimal(18,2))
--------------------
.33
(所影响的行数为 1 行)
declare @val dec(18,2)
set @val='1.20'
select LEFT(@val,LEN(@val)-PATINDEX('%[^0]%.%',REVERSE(@val))+1)
/**
-----------------------------------------
1.2
(1 行受影响)
**/
用decimal(15,2)类型取值,select cast(0.3355555555555 as decimal(15,2)) =0.34,如果不想四舍五入用round处理下