Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Rounding Issues

Author  Topic 

bogus
Starting Member

41 Posts

Posted - 2008-02-13 : 19:31:28
Man... SQL does not make this easy... And right now, all I want to do is make sense of this mess.


SELECT
Vendor_Catalog_Num,
Unit_Price,
List_Price,
ROUND(Unit_Price, 2) AS New_Unit_Price,
ROUND(List_Price, 2) AS New_List_Price
FROM Catalog
WHERE Unit_Price > 0 and List_Price > 0 and vendor_Catalog_Num = 'XXXXXXXXX'


Output:



Vendor Part # Unit Price List Price New Unit Price New List Price
XXXXXXXX 177.59999999999999 296.0 177.59999999999999 296.0


I have scanned the referenced "Train Wreck" threads regarding bankers rounding... fine and dandy... I just wanna know why this isn't rounding at all!

Thanks!

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2008-02-13 : 20:16:15
I hate floats:

declare @f float(53)
set @f = 177.59999999999999
select round(@f, 2)
,round(convert(numeric(38,9), @f),2)

go
declare @f decimal(38,9)
set @f = 177.59999999999999
select round(@f, 2)

output:
----------------------------------------------------- ----------------------------------------
177.59999999999999 177.600000000


----------------------------------------
177.600000000



Be One with the Optimizer
TG
Go to Top of Page
   

- Advertisement -