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 2005 Forums
 Transact-SQL (2005)
 Decimal places are not calculate correctly.

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.000000000000000

But 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]
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-12-16 : 10:16:07
SELECT 100 * 25000/700.000000000000000
Go to Top of Page

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"
Go to Top of Page

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.
Go to Top of Page

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
Go to Top of Page

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 result

Thanks

Go to Top of Page

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 result

Thanks




what does this give you

SELECT 100.000000000000000 * (field1/field2) from table

Go to Top of Page

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"
Go to Top of Page
   

- Advertisement -