 |
|
 |
|
Next: ADS Refresh
|
| Author |
Message |
External

Since: Nov 20, 2008 Posts: 3
|
(Msg. 1) Posted: Thu Feb 12, 2009 8:28 am
Post subject: SQL2005 Round Archived from groups: microsoft>public>sqlserver>programming (more info?)
|
|
|
I'm currently creating a stored procedure that needs to round a number to a
specified "fraction". The stored procedure is being taken from a VB6
function.
I have everything working fine with one exception, the Round function. When
VB6 rounds 0.5 (or exactly 1/2), it rounds down to 0 (zero), however SQL
2005 rounds 0.5 (or exactly 1/2) up to 1.
In both places I'm using ROUND(number, 0).
Any ideas how to get SQL to round 0.5 down to zero?
Thanks,
James Walker >> Stay informed about: SQL2005 Round |
|
| Back to top |
|
 |  |
External

Since: Jan 30, 2008 Posts: 2
|
(Msg. 2) Posted: Thu Feb 12, 2009 8:28 am
Post subject: Re: SQL2005 Round [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
On Feb 12, 9:28 pm, "James Walker" wrote:
> I'm currently creating a stored procedure that needs to round a number to a
> specified "fraction". The stored procedure is being taken from a VB6
> function.
>
> I have everything working fine with one exception, the Round function. When
> VB6 rounds 0.5 (or exactly 1/2), it rounds down to 0 (zero), however SQL
> 2005 rounds 0.5 (or exactly 1/2) up to 1.
>
> In both places I'm using ROUND(number, 0).
>
> Any ideas how to get SQL to round 0.5 down to zero?
>
> Thanks,
> James Walker
ROUND(1/2,-1) >> Stay informed about: SQL2005 Round |
|
| Back to top |
|
 |  |
External

Since: Aug 24, 2003 Posts: 1744
|
(Msg. 3) Posted: Thu Feb 12, 2009 9:25 am
Post subject: Re: SQL2005 Round [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
James
I got 0 in SS2005(SP3)
SELECT ROUND(1/2,0)
SELECT FLOOR(0.5)
"James Walker" wrote in message
> I'm currently creating a stored procedure that needs to round a number to
> a specified "fraction". The stored procedure is being taken from a VB6
> function.
>
> I have everything working fine with one exception, the Round function.
> When VB6 rounds 0.5 (or exactly 1/2), it rounds down to 0 (zero), however
> SQL 2005 rounds 0.5 (or exactly 1/2) up to 1.
>
> In both places I'm using ROUND(number, 0).
>
> Any ideas how to get SQL to round 0.5 down to zero?
>
> Thanks,
> James Walker
> >> Stay informed about: SQL2005 Round |
|
| Back to top |
|
 |  |
External

Since: Nov 20, 2008 Posts: 3
|
(Msg. 4) Posted: Thu Feb 12, 2009 11:44 am
Post subject: Re: SQL2005 Round [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
Thanks for the replies, however I should have explained in a little more
detail.
The "number" I'm rounding is the numerator of a fraction. I'm passing in the
denominator to round to.
As an example my number could be 5.03125 and round to .0625 (1/16). Where
@Dimension is 5.03125 and @RoundTo is .0625
Where is my sql statement:
FLOOR(@Dimension) + ROUND((@Dimension - FLOOR(@Dimension)) * @RoundTo, 0) /
@RoundTo
I would a result of 5, however the above statement returns 5.0625.
Thanks,
James Walker
"Uri Dimant" wrote in message
> James
> I got 0 in SS2005(SP3)
> SELECT ROUND(1/2,0)
>
> SELECT FLOOR(0.5)
>
>
>
> "James Walker" wrote in message
>
>> I'm currently creating a stored procedure that needs to round a number to
>> a specified "fraction". The stored procedure is being taken from a VB6
>> function.
>>
>> I have everything working fine with one exception, the Round function.
>> When VB6 rounds 0.5 (or exactly 1/2), it rounds down to 0 (zero), however
>> SQL 2005 rounds 0.5 (or exactly 1/2) up to 1.
>>
>> In both places I'm using ROUND(number, 0).
>>
>> Any ideas how to get SQL to round 0.5 down to zero?
>>
>> Thanks,
>> James Walker
>>
>
> >> Stay informed about: SQL2005 Round |
|
| Back to top |
|
 |  |
External

Since: Aug 20, 2008 Posts: 672
|
(Msg. 5) Posted: Thu Feb 12, 2009 12:29 pm
Post subject: Re: SQL2005 Round [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
If I run this I get 5 as result:
DECLARE @Dimension DECIMAL(12, 6) = 5.03125;
DECLARE @RoundTo DECIMAL(12, 6) = 0.0625;
SELECT FLOOR(@Dimension) +
ROUND((@Dimension - FLOOR(@Dimension)) * @RoundTo, 0) /
@RoundTo;
--------------
5.000000000000
--
Plamen Ratchev
http://www.SQLStudio.com >> Stay informed about: SQL2005 Round |
|
| Back to top |
|
 |  |
External

Since: Aug 20, 2008 Posts: 672
|
(Msg. 6) Posted: Thu Feb 12, 2009 1:36 pm
Post subject: Re: SQL2005 Round [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
|
|
| Back to top |
|
 |  |
| Related Topics: | MS SQL ROUND() vs. VB ROUND() - -- Luis Garcia IT Consultant
why does CAST round - declare @test decimal(18,9) SET @test = CAST('12.75' AS decimal) PRINT @test result = 13.00 Why not 12.75, what am i doing wrong??
round function does not work as expected - I am using the round function in a view in order to display data to a specified number of decimal places. In general it displays the data as expected but occasionally there are values that are displayed to many decimal places. Maybe I should be usin...
Hourly job running exactly 5 minutes after a round hour - Hi Expert, I defined a job that runs every hour using the job wizard. However, I would like it to start running 5 minutes after each round hour i.e. 12:05:00, 13:05:00, 14:05:00 etc How can I define such scheduling? Thanks, Avi
SQL2005 blocking - SQL2005 server was blocking, running at 100% of processor, and the program didn't work. So I go to activity monitor to see, hat is going there. When I opened the only active proccess on my database, I saw the following TSQL command batch: create table... |
|
You can post new topics in this forum You can reply to topics in this forum You can edit your posts in this forum You can delete your posts in this forum You can vote in polls in this forum
|
|
|
|
 |
|
|