문제

What is the best data type in SQL Server 2008 R2 to store a value like 1.74269E-06?

I am trying to put as float, but the value always zero. Advice please.

TIA.

Regards,

도움이 되었습니까?

해결책

When I insert that value into a datatype of float, it isn't zero.

You might be accidentally casting it to INT or displaying it incorrectly.

If your values are going to be very large or very small (and can't be held in DECIMAL) then you'll need to use FLOAT

DECLARE @Table TABLE (F FLOAT, D DECIMAL(19,7))

INSERT INTO @Table (F,D)
VALUES(1,1)

INSERT INTO @Table (F,D)
VALUES(1.74269E-06,1.74269E-06)

-- I can see the float here in exponential format
SELECT F,D FROM @Table

-- I can see it here in decimal format
SELECT CONVERT(DECIMAL(19,7),F),D FROM @Table

-- But if I cast to INT it disappears.
SELECT CONVERT(INT,F),D FROM @Table

다른 팁

Use decimal instead.

decimal [ (p[ ,s] )] and numeric[ (p[ ,s] )] Fixed precision and scale numbers. When maximum precision is used, valid values are from - 10^38 +1 through 10^38 - 1. The ISO synonyms for decimal are dec and dec(p, s). numeric is functionally equivalent to decimal.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top