Storing BigDecimal in SQL Server

C

cliodhna.hurst

Hi,

I need to store very small numbers in my database, generally something
like 1.2516E-128. I'm using BigDecimal is Java to manipulate these
numbers however when storing them in MS SQL server as a double they are
converted to 0. SQL Server will only allow a a double with a scale of
maximum size 18.

I've also tried to use the Float object to store and manipulate the
numbers in Java instead of BigDecimal. Once they are smaller than E-47
however, Java stores them as 0 also.

Does anyone know of a way to manipulate these numbers in Java and then
store them in MS SQL Server?

Thanks
Cli
 
D

Dag Sunde

Hi,

I need to store very small numbers in my database, generally something
like 1.2516E-128. I'm using BigDecimal is Java to manipulate these
numbers however when storing them in MS SQL server as a double they are
converted to 0. SQL Server will only allow a a double with a scale of
maximum size 18.

I've also tried to use the Float object to store and manipulate the
numbers in Java instead of BigDecimal. Once they are smaller than E-47
however, Java stores them as 0 also.

Does anyone know of a way to manipulate these numbers in Java and then
store them in MS SQL Server?

Have you tried the SQL type 'decimal(precision, scale)'?

precicion: total number of digits
scale : number of digits after the decimal-point

ConlumnName DECIMAL(130, 128) NOT NULL ...

Note! I never tried DECIMAL with this large scale, but it might be
worth looking into...
 
C

cliodhna.hurst

Hi Dag,

The maximum precision allowed by MS SQL on a decimal is 38 and the max
scale is 18. Have you used a decimal with a larger precision and scale
than this?

Cli
 
D

Dag Sunde

Hi Dag,

The maximum precision allowed by MS SQL on a decimal is 38 and the max
scale is 18. Have you used a decimal with a larger precision and scale
than this?

No, sorry... I said I hadn't tested it...

Looks like you have to make a hybrid datatype in MS SQL, then...
You could for example store the exponent in one column, and the mantissa
in another... Ugly, I Know,but...
 
T

TechBookReport

Hi Dag,

The maximum precision allowed by MS SQL on a decimal is 38 and the max
scale is 18. Have you used a decimal with a larger precision and scale
than this?

Cli
An obvious hack is to store as a string, and parse back into a
BigDecimal after reading back into your code. But this depends what it
is you're doing in SQL Server. If it's just storage then it should be
OK, if you're using SQL for manipulating and arithmetic than it it's not
much help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,157
Latest member
MercedesE4
Top