Link to home
Start Free TrialLog in
Avatar of Camillia
CamilliaFlag for United States of America

asked on

Multiply and round down

There's a VB6 code here and I took the logic and converted it to a stored proc.

VB code value is 5626 so it rounds down. The stored proc I have shows 5627. So, in below code, how can I round down?

This is SQL 2014

declare @settledtest decimal(5,5)
declare @settledWeight int

set @settledtest = 0.41250
set @settledWeight = 13640

select @settledTest * @settledWeight   ---gets 5626.50000
select Round(@settledTest * @settledWeight,0)  --  gets 5627.00000. *** This is what I have in the stored proc. How can I round down?

Open in new window

SOLUTION
Avatar of Sean Stuber
Sean Stuber

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Camillia

ASKER

I did this,

Round(Floor(@settledTest * @settledWeight),0)

Open in new window


Different than casting as int?
Avatar of Sean Stuber
Sean Stuber

why round after using Floor?

it's ok to do so, but it's an extra function call without adding value.

it's not the same thing as casting to Int though, because the cast will actually change the result type.  That may or may not be ok, but it is functionally different.
Thanks, let me run some more values
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I'll check the VB code again. I think what I have might not be correct. I just ran some more tests and I don't think I can just round down.

I'll post back tomorrow (or close this and reopen a new one)
I'll run more tests in the morning.