| Author |
Topic |
|
kamal.A
Yak Posting Veteran
70 Posts |
Posted - 2008-12-16 : 10:11:19
|
| Hi All,I'm using the following sql statement in SQL server 2005.SELECT CAST(100 * 25000)/700) As Decimal(29,15))The result returned by SQL is 3571.000000000000000But our calculate retuned 3571.42857142871428714.I need the exact calc result.How can i achieve this from sql.Please help me.Kamal. |
|
|
sakets_2000
Master Smack Fu Yak Hacker
1472 Posts |
Posted - 2008-12-16 : 10:15:51
|
| [code]SELECT cast (100.0*25000 / 700 As Decimal(29,15))[/code] |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-12-16 : 10:16:07
|
| SELECT 100 * 25000/700.000000000000000 |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-12-16 : 10:20:27
|
To make sure not only six decimal places are used, force one of the fixed values to DECIMAL(29, 15).SELECT CAST(CAST(100 AS DECIMAL(29, 15)) * 25000 / 700 AS DECIMAL(29, 15)) E 12°55'05.63"N 56°04'39.26" |
 |
|
|
kamal.A
Yak Posting Veteran
70 Posts |
Posted - 2008-12-16 : 11:20:34
|
| Thanks for all,all the 25000 and 700 values are came from table field, that fields datatype is decimal(29,15), that time it is not work perfectly.What is the reason? Please. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-12-16 : 11:24:30
|
| http://sqlblogcasts.com/blogs/madhivanan/archive/tags/Implicit+conversion/default.aspx |
 |
|
|
kamal.A
Yak Posting Veteran
70 Posts |
Posted - 2008-12-17 : 01:29:28
|
| Thanks for the answer. I have given the as per madivanan post, but I have only get the 6 digit precision, but I need above 12 digits. How can I get my resultThanks |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-12-17 : 01:33:26
|
quote: Originally posted by kamal.A Thanks for the answer. I have given the as per madivanan post, but I have only get the 6 digit precision, but I need above 12 digits. How can I get my resultThanks
what does this give youSELECT 100.000000000000000 * (field1/field2) from table |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-12-17 : 02:20:48
|
Beware of using leading zeros. Different number of leading zeros gives different result back.Use FLOAT as SELECT 100.0E * field1 / field2 from table E 12°55'05.63"N 56°04'39.26" |
 |
|
|
|