Reputation: 2120
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
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
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
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
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