Abdul
Abdul

Reputation: 2120

Store very large numbers in scientific notation form in SQL

We have an application which returns result of large calculations in exponent to base form like 1.8e+6.

We need to save this value in database. Can we store this in database as integer or it should be converted to a number first ?

please help

Upvotes: 0

Views: 1288

Answers (4)

John Cappelletti
John Cappelletti

Reputation: 81990

SQL will consume the scientific notation directly

Select val1 = 1.8e+6
      ,val2 = cast(1.8e+6 as bigint)
      ,val3 = cast('1.8e+6' as float) 

Returns

val1    val2    val3
1800000 1800000 1800000

Upvotes: 1

Paweł Dyl
Paweł Dyl

Reputation: 9143

I think the biggest you can use is:

DECLARE @d float(53)

It ranges between -1.79E+308 and 1.79E+308

Upvotes: 2

Gordon Linoff
Gordon Linoff

Reputation: 1270421

SQL Server supports floating point numbers, both 4-byte and 8-byte. These accept constants such as 1e4 in exponential notation. They are also fully supported by the mathematical functions.

You can read about the types in the documentation.

Upvotes: 3

Erik Blomgren
Erik Blomgren

Reputation: 886

You can insert 1.8e+6 directly into a table column of type "int", it will be interpreted (Tested with SQL Server 2014).

Beware that "int" only can handle numbers as large as 1.8e+31, for larger numbers you'll need to use bigint.

Upvotes: 0

Related Questions