Hi all,
has anyone of you an approved banker's round function for sql?
IT needs to work with positive as well as with negative amounts...
I'd be very very happy if anyone could help me out!
Best regards
Peter Widmercan you give an example of what the output should be for +ve and -ve values?|||Hi Omnibuzz,
I'll try to get some samplevalues until tommorow from the bank. I'll post
them as soon as I got them.
Thank you!
"Omnibuzz" <Omnibuzz@.discussions.microsoft.com> schrieb im Newsbeitrag
news:730B6730-DBA8-49D5-BC30-0F16318CE506@.microsoft.com...
> can you give an example of what the output should be for +ve and -ve
> values?|||Hi, Peter
This KB article is a good starting point for informations about various
rounding methods:
http://support.microsoft.com/?kbid=196652
Here is a T-SQL function that performs Banker's rounding (tested with
the sample data provided in the above article):
CREATE FUNCTION BankersRound(@.Number numeric(38,18))
RETURNS numeric(20,0) AS BEGIN
DECLARE @.Result numeric(20,0)
SET @.Result=ROUND(@.Number,0)
IF ABS(@.Number-@.Result)=0.5 BEGIN
IF @.Result*0.5<>ROUND(@.Result*0.5,0) BEGIN
SET @.Result=@.Result-SIGN(@.Number)
END
END
RETURN @.Result
END
Razvan
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment