sql - How to change number of digits after decimal point? -


i have line in query:

case when count(n.counter) <> 0 (cast(count(n.counter) float)/count(t.counter)) * 100 else 0 end percent 

i'm getting results 79.565974946. want result 80% (with no digits after decimal point , '%' sign). how can that?

you need round , then, because you're trying formatting, convert string before adding %:

convert(varchar(20), round( case when count(n.counter) <> 0       (cast(count(n.counter) float)/count(t.counter)) * 100      else 0 end ,0)) + '%' percent 

also, there may typo here - looks you're trying avoid divide 0 error, you're testing wrong operand (n.counter rather t.counter) may still division 0 code.


Comments

Popular posts from this blog

python - Healpy: From Data to Healpix map -

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -