使用逗号分隔符获取浮点值
Get Float value with Comma separtor
我是 Sql server ce
的新手。我的 table 有浮点值。我想要 select 以逗号分隔和小数位浮动。像这样
table姓名table1
val
1220333
222
36535
我想要这样的结果
val
12,20,333.00
222.00
36,535.00
喜欢印度卢比
正在使用 Sql server ce 3.5
DECLARE @Table1 TABLE
(val int)
;
INSERT INTO @Table1
(val)
VALUES
(1220333),
(222),
(36535)
;
select convert(varchar(50), CAST(val as money), -1) amount from @Table1
select FORMAT(CAST(val AS MONEY),'N','en-in') amount from @Table1
或
函数
create function to_indian_currency(@n decimal(25,5))
returns varchar(100) as
BEGIN
declare @a varchar(100) = cast(@n as varchar(100))
declare @dec_part varchar(100) =
(select substring(@a, charindex('.',@a), len(@a)-charindex('.',@a)+1))
declare @int_part varchar(100) = (select left(@a, charindex('.',@a)-1))
declare @f int = cast(@int_part as bigint)%1000
declare @q int = cast(@int_part as bigint)/1000
declare @final varchar(100) = ''
while @q > 0
begin
set @final = cast(@q%100 as varchar) + ',' + @final
set @q = @q/100
end
RETURN @final + cast(@f as varchar) + @dec_part
END
select dbo.to_indian_currency(val) 来自@Table1
我是 Sql server ce
的新手。我的 table 有浮点值。我想要 select 以逗号分隔和小数位浮动。像这样
table姓名table1
val
1220333
222
36535
我想要这样的结果
val
12,20,333.00
222.00
36,535.00
喜欢印度卢比
正在使用 Sql server ce 3.5
DECLARE @Table1 TABLE
(val int)
;
INSERT INTO @Table1
(val)
VALUES
(1220333),
(222),
(36535)
;
select convert(varchar(50), CAST(val as money), -1) amount from @Table1
select FORMAT(CAST(val AS MONEY),'N','en-in') amount from @Table1
或
函数
create function to_indian_currency(@n decimal(25,5))
returns varchar(100) as
BEGIN
declare @a varchar(100) = cast(@n as varchar(100))
declare @dec_part varchar(100) =
(select substring(@a, charindex('.',@a), len(@a)-charindex('.',@a)+1))
declare @int_part varchar(100) = (select left(@a, charindex('.',@a)-1))
declare @f int = cast(@int_part as bigint)%1000
declare @q int = cast(@int_part as bigint)/1000
declare @final varchar(100) = ''
while @q > 0
begin
set @final = cast(@q%100 as varchar) + ',' + @final
set @q = @q/100
end
RETURN @final + cast(@f as varchar) + @dec_part
END
select dbo.to_indian_currency(val) 来自@Table1