select 2/3 how to result 0.67 via sql sever 2005
A:
Hi
Select cast(2.0/3.0 as decimal(3,2)) as result
, should help.
cheers
Andriyev
2010-01-22 04:31:19
A:
Try this
select cast(ROUND(2/3.0, 2) as decimal(2,2))
Hope that will help.
Asim Sajjad
2010-01-22 04:34:13
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
2010-01-22 04:40:06
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
2010-01-22 04:53:38