Drop 0 value in decimal places

后端 未结 4 1924
遥遥无期
遥遥无期 2021-01-26 18:55

I want to ask if anybody know the query to drop the 0 value in decimal..

E.g : A field name percent have these values

Percent

770.00000000000000000000,

4条回答
  •  星月不相逢
    2021-01-26 19:49

    This rather nasty TSQL might just do the job :

    select 
      case 
        right(
           cast(cast([percent] as decimal(9,2)) as nvarchar(11))
        ,2)
    
        when '00' then cast(cast([percent] as int) as nvarchar(11)) as [percent]
        else cast(cast([percent] as decimal(9,2)) as nvarchar(11)) as [percent]
    
     end
    from table
    

    of course it is always returning a string, but that's inherent to your demands, you are looking for a representation for a value...

    I think you should postpone that representation to where it makes more sense (report, datagrid?) and you have more tools (like string.format kinda tools) to do the job better.

提交回复
热议问题