views:

33

answers:

5

select 2/3 how to result 0.67 via sql sever 2005

A: 
SELECT ROUND(2.0/3.0, 2)
Aaronaught
A: 

Hi

Select cast(2.0/3.0 as decimal(3,2)) as result, should help.

cheers

Andriyev
A: 

Try this

select cast(ROUND(2/3.0, 2) as decimal(2,2))

Hope that will help.

Asim Sajjad
A: 
ALTER FUNCTION GetDecimalFromDivided(@interger1 INT, @interger2 INT , @round INT) 
RETURNS FLOAT AS
Begin
RETURN  ROUND(@interger1/cast(cast(@interger2 AS VARCHAR) + '.0' AS FLOAT),@round)
END
monkey_boys
A: 
SELECT 2.0/3.0 AS RawResult

Format in client

Comments on the function in your answer...

ALTER FUNCTION GetDecimalFromDivided (@float1 float, @float2 float, @round INT) 
RETURNS float AS
Begin
RETURN ROUND (@float/@float2, @round)
END
  • Why send integer in?
  • round is meaningless with a return type of float. You may get 0.6700000000001 for example
  • If you want to fix decimal places, use decimal(p,2). But then your ROUND is useless.

You really should format in the client!

gbn