Home > Database > Mysql Tutorial > sql 去零函数 datagridview中数字类型常出现后面的零不能去掉

sql 去零函数 datagridview中数字类型常出现后面的零不能去掉

WBOY
Release: 2016-06-07 17:58:25
Original
1062 people have browsed it

sql 去零函数 datagridview中数字类型常出现后面的零不能去掉,此函数在sql中使用即可

代码如下:
declare @bl decimal(10,6),@num int,@num1 int ,@str char(20),@str1 char(20),@str2 char(20),@str3 char(20),@zx int,@zx1 int
set @bl=1110.10000
set @str1=ltrim(REVERSE(cast(@bl as char(30)))) ---颠倒
print @str1
set @zx1=cast(@bl as int)
set @str2=cast(@zx1 as char(10)) --取整数部分
print @zx1
set @num=len(@str2)
print @num
set @num1=charindex('.',@str1)
print @num1
set @str1=substring(@str1,0,@num1)
set @zx1=cast(@str1 as int)
print @str1
set @str3=ltrim(REVERSE(cast(@zx1 as char(10)))) --取小数部分
if @str3=0
set @str=rtrim(cast(@str2 as char(20)))
else
--print @str2
--print @str3
set @str=rtrim(cast(@str2 as char(20)))+'.'+rtrim(cast(@str3 as char(6)))
print @str
---set @str3=cast(@str2 as decimal(10,6))
Related labels:
sql
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template