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)
 Casting to numeric will auto round?

Author  Topic 

ajthepoolman
Constraint Violating Yak Guru

384 Posts

Posted - 2003-01-09 : 15:54:42
Hello all.

Would this round a value?

CAST(REPLACE(UDFED.numDollars, '$', '') AS NUMERIC)

If UDFED.numDollars is coming from a column that is type varchar(50)?

My database table is showing $130.52, but when I export this value to a column of type Numeric, it comes out $131.

Any ideas?

Aj

robvolk
Most Valuable Yak

15732 Posts

Posted - 2003-01-09 : 16:07:10
You need to specify a scale and precision:

SELECT CAST(Replace(UDFED.numDollars, '$', '') AS numeric(10,2))

That will give you a 10-digit (max) number with 2 decimal places.

Go to Top of Page

ajthepoolman
Constraint Violating Yak Guru

384 Posts

Posted - 2003-01-09 : 17:41:18
Oh, Duh!

Sometimes the fundamentals get forgotten.

Thanks!

Aj

Go to Top of Page
   

- Advertisement -