Drop 0 value in decimal places

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

    You could use a combination of DECIMAL and FLOAT. Decimal first to round it down to 2 deciaml places, then float to remove unwanted 0's

    e.g.

    select cast(cast([Percent] as decimal(9,2)) AS FLOAT) as [Percent] 
    

    With the example of 340.69999999999999, first it round to 340.70, then it takes away the zero giving you 340.7. As with any rounding some precision will be lost.

提交回复
热议问题