0

Hi I have some problem which I can't solve, maybe some of you can help me I need to show result of division.

select 50/200 as we all know it supposed be 0.25, however, I got 0 so them i try this

SELECT ROUND(CAST(50 AS NUMERIC(18,2) )/ CAST(200 AS NUMERIC(18,2)),2)

which gives me 0.25000000000000000000

I then tried to use Round

select cast(round(50/200,2) as numeric(36,2))

but its returning me 0.00

How would i fix this to just show 0.25?

austin wernli
  • 1,801
  • 12
  • 15
Andrey
  • 1,629
  • 13
  • 37
  • 65

1 Answers1

1

You could just do this:

SELECT CAST ( ROUND ( 50 / 200.0 , 2 ) AS numeric ( 18 , 2 )) ;

EDIT:

Per your comment, you could modify it to this.

SELECT CAST ( ROUND ( @int1 / CAST ( @int2 AS numeric ( 18 , 2 )) , 2 ) AS numeric ( 18 , 2 )) ;
austin wernli
  • 1,801
  • 12
  • 15
  • it works in this case, but the problem in reall query it looks like SELECT CAST ( ROUND ( `column1 / column2`, 2 ) AS numeric ( 36 , 2 )) so i cant just simply add .0 to the end – Andrey Jan 19 '15 at 15:55
  • You gave me a -1 because i answered your question, but did not answer your unlisted question? – austin wernli Jan 19 '15 at 21:20