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 |
|
Vaishu
Posting Yak Master
178 Posts |
Posted - 2008-03-19 : 12:58:41
|
Hi I am using below code in sql procedure and the data types are below.b.price -nvarchar 255b.quantity - nvarchar 255a.NumPacks - numericcast(b.price as decimal(19,2)) / cast(a.NumPacks * b.quantity as decimal(19,2)) AS UNITPRICE When I run the above code I should get the result as below1400.99Instead I am getting as below1400.990000000000000000Please help. Advance Thanks. |
|
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2008-03-19 : 13:27:02
|
| Those values are the same. You can format any way you want at your client when outputting your results.You also have a really bad design -- you should be using proper data types for your columns and your data, never use NVARCHAR when your data is numeric.- Jeffhttp://weblogs.sqlteam.com/JeffS |
 |
|
|
modi_sanjay
Starting Member
9 Posts |
Posted - 2008-03-19 : 15:38:25
|
| HiYou have to put cast outside for trimming the getting result. But i recommended to you please keep column data type as appropriatecast( put your above code here as decimal(19,2))Likecast( cast(b.price as decimal(19,2)) / cast(a.NumPacks * b.quantity as decimal(19,2)) as decimal(19,2)) AS UNITPRICE |
 |
|
|
blindman
Master Smack Fu Yak Hacker
2365 Posts |
Posted - 2008-03-19 : 19:06:42
|
| ...or you might want to try casting price as money rather than decimal.e4 d5 xd5 Nf6 |
 |
|
|
Vaishu
Posting Yak Master
178 Posts |
Posted - 2008-03-20 : 08:35:36
|
HiThanks a lot. It worksquote: Originally posted by modi_sanjay HiYou have to put cast outside for trimming the getting result. But i recommended to you please keep column data type as appropriatecast( put your above code here as decimal(19,2))Likecast( cast(b.price as decimal(19,2)) / cast(a.NumPacks * b.quantity as decimal(19,2)) as decimal(19,2)) AS UNITPRICE
|
 |
|
|
modi_sanjay
Starting Member
9 Posts |
Posted - 2008-03-20 : 13:09:29
|
You Welcome  quote: Originally posted by Vaishu HiThanks a lot. It worksquote: Originally posted by modi_sanjay HiYou have to put cast outside for trimming the getting result. But i recommended to you please keep column data type as appropriatecast( put your above code here as decimal(19,2))Likecast( cast(b.price as decimal(19,2)) / cast(a.NumPacks * b.quantity as decimal(19,2)) as decimal(19,2)) AS UNITPRICE
Thanks & RegardsSanjay Modi |
 |
|
|
|
|
|
|
|