SQL查詢金額去掉小數點後面的零

2021-09-08 16:15:23 字數 1168 閱讀 7241

如果是2005以上版本,直接:

select

ltrim

(cast

(col

asfloat

)) fromtb

例如:

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處理下

sql 中去掉小數後面的0

create function clearzero invalue varchar 50 returns varchar 50 asbegin declare returnvalue varchar 20 if invalue set returnvalue 空的時候為空 else if chari...

C Double保留小數點後面位數

double test1 1000.0 double test2 1000.12345 double test3 1000.1289 int test4 1000 string test5 1000 string test6 1000.12345 string test7 1000.1289 con...

C Double保留小數點後面位數

double salary1 10000.0 double salary2 10000.12345 double salary3 10000.1289 int salary4 10000 string salary5 10000 string salary6 10000.12345 string s...