Drop 0 value in decimal places

后端 未结 4 1914
遥遥无期
遥遥无期 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:40

    You can use CONVERT function twice, once to drop 0 by converting to float and once to convert it to varchar with style 128

    DECLARE @Sample AS TABLE
        (
         SomeNumber DECIMAL(26, 12)
        )
    
    INSERT INTO @Sample
        VALUES  ( 770.00000000000000000000 )
    ,           ( 340.670000000000000000000 )
    ,           ( 96.00000000000000000000 )
    ,           ( 4400.56000000000000000000 )
    ,           ( 109.89000000000000000000 )
    ,           ( 109.00000000000000000000 )
    ,           ( 37.00000000000000000000 )
    
    
    SELECT CONVERT(VARCHAR(25), CONVERT(FLOAT, SomeNumber), 128) AS NoZeros
        FROM @Sample
    

提交回复
热议问题