让小数转化为百分数.
如0.5转化成50%

解决方案 »

  1.   

    declare @f float
    set @f=0.5
    select rtrim(@f*100)+'%'
    /*                        
    ----------------------- 
    50%
    */
      

  2.   

    这个得自己写
    declare @t decimal(10,1),@s varchar(20)
    set @t=0.5
    set @s=cast(0.5*100 as varchar)+'%'
    select @s
      

  3.   

    只能转化成字符串再加个百分号
    declare @n numeric(18,5)
    set @n=0.512367
    select str(@n*100,5,2)+'%'--转化成有2位小数,长度为5的字符串,算上小数点
    --结果
    --51.24%
      

  4.   

    最好不要在SQL改,很多控件都能显示不同的格式的
      

  5.   

    cast(小数*100 as varchar) + '%'
      

  6.   


    IF EXISTS( Select  Name 
               From    sysobjects
               Where   Name =N'QueryPriceInList'
               And     Type = 'P')
       DROP PROCEDURE QueryPriceInList
    GO
    CREATE PROCEDURE QueryPriceInList @SelectPrice Decimal(10,1), @MaxPrice Decimal(10,1)
    AS
    Set NoCount on 
    Set Ansi_nulls Off 
    Set Ansi_Warnings Off  Declare @PriceRangePercent varchar(20)Select @PriceRangePercent = Cast(((@SelectPrice - @MaxPrice)/@MaxPrice)*100 as varchar)+'%'  Create Table #a(Price Varchar(20))
    Insert Into #a Values (@PriceRangePercent)
    Select Price From #a
    Drop Table #a
    GO
    EXEC QueryPriceInList '10','100'
    /*得到
    Price                
    -------------------- 
    -90.000000000000%我对数据转换老是不懂,我想得到-90.000%这种结果,该怎么修改?
      

  7.   

    cast(cast(小数*100 as decimal(18,3) as varchar)) + '%'
      

  8.   

    declare @cnt as decimal(18,3)
    set @cnt = -0.9select cast(cast(@cnt*100 as decimal(18,3)) as varchar) + '%'/*
                                    
    ------------------------------- 
    -90.000%(所影响的行数为 1 行)
    */