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)
 cast problem

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2006-02-16 : 07:45:12
ashish908 writes "I have a table called "ExchangeRate"

Columns

ID numeric
ExchangeRate float
DecimalPlaces smallint


I want the query to be like this

Select id, (cast(exchangerate as decimal(10,decimalplaces)) from ExchangeRate

The above query gives an error, but if i explicitly specify an integer value in place of decimalplaces in the above query, it works fine.

How do i make the query work with decimalplaces?"

robvolk
Most Valuable Yak

15732 Posts

Posted - 2006-02-16 : 07:51:00
SELECT id, Round(exchangerate, decimalplaces) FROM ExchangeRate

If you actually need it formatted as a 10 digit number:

SELECT id, Str(exchangerate, 10, decimalplaces) FROM ExchangeRate

If you truly need to store an exchange rate with up to 10 decimal places, then define ExchangeRate as decimal(20,10). Float is an approximate numeric format, you will lose precision and have rounding errors when using it, completely negating the point of needing exact decimals.
Go to Top of Page
   

- Advertisement -