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
 General SQL Server Forums
 New to SQL Server Programming
 what SQL Server data type

Author  Topic 

M_N_M
Starting Member

21 Posts

Posted - 2011-06-08 : 12:58:11
Hello,

what SQL Server data type can be used to act like a "double" in foxpro?

I want to store numbers with an unlimited number of decimals (eg 1/3 = 0.3333333333333; 1/876 = 0.00114155...)

I know I can use a "float" for this but float's also SHOW all the decimals.
In our old database, there was data type "double" and you could specify how much decimal numbers you want to show.

E.g.: double(3) shows "0.33333333..." as 0.333 but when you calculate, it calculates with all the decimal digits.

Is there something like that in SQL Server?
If I use "decimal", it displays AND calculates only with the decimals specified (1/3 = 0.333 stored and displayed)

Thanks in advance!

robvolk
Most Valuable Yak

15732 Posts

Posted - 2011-06-08 : 13:01:54
Nope, float or decimal are your only options. Keep in mind that float is an approximate data type and may not round consistently.
Go to Top of Page

M_N_M
Starting Member

21 Posts

Posted - 2011-06-09 : 01:24:00
ok but how can you store 1/3 most accurate? In a decimal with a lot of decimal places reserved or in a float?
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2011-06-09 : 07:51:16
Decimal will always be more precise, and you can store more digits (up to 38) than float. A better description of decimal is fixed-point, and float as floating-point, to describe how the decimal is set.
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2011-06-09 : 08:00:59
Why store the quotient at all? Why not store the divisor and dividend only? That way you will always be exact.
And when you need the result, calculate it only then and reduce the size of rounding errors.



N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page

M_N_M
Starting Member

21 Posts

Posted - 2011-06-09 : 08:31:00
@Peso: it's just an example.. The numbers are in a lot of tables and it's not possible to store both (too much work to change everything)

I'll use a decimal with more decimals that will hopefully help me, thx!
Go to Top of Page
   

- Advertisement -