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.
| Author |
Topic |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2006-02-16 : 07:45:12
|
| ashish908 writes "I have a table called "ExchangeRate"ColumnsID numericExchangeRate floatDecimalPlaces smallintI want the query to be like thisSelect id, (cast(exchangerate as decimal(10,decimalplaces)) from ExchangeRateThe 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 ExchangeRateIf you actually need it formatted as a 10 digit number:SELECT id, Str(exchangerate, 10, decimalplaces) FROM ExchangeRateIf 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. |
 |
|
|
|
|
|