# Convert / Decimal / Float - Microsoft SQL / MS SQL Server

I need to convert this example in 16 decimals number. CREATE TABLE #TMP_APLICACAO ( [VL_APLICACAO] [MONEY], [NR_QUANTIDADE] [NUMERIC] (28,16), [VL_PU_OPERACAO] [NUMERIC] (28,16) ) declare vl_pu_operacao numeric(28,16) INSERT INTO #TMP_APLICACAO VALUES ( 3103.40, 3.00, 0) select vl_pu_operacao = VL_APLICACAO / NR_QUANTIDADE FROM #TMP_APLICACAO SELECT VL_PU_OPERACAO PS. How can I have to do to see the result in 16 decimal number : 1034.4666666666666667 ? I use select vl_pu_operacao = CONVERT(decimal (28,16),VL_APLICACAO / NR_QUANTIDADE) FROM #TMP_APLICACAO , but the results is 1034.4666666666 and itīs wrong. DROP TABLE #TMP_APLICACAO...

1. ## Convert / Decimal / Float

I need to convert this example in 16 decimals number.

CREATE TABLE #TMP_APLICACAO
(
[VL_APLICACAO] [MONEY],
[VL_PU_OPERACAO] [NUMERIC] (28,16)
)

declare vl_pu_operacao numeric(28,16)

INSERT INTO #TMP_APLICACAO VALUES ( 3103.40, 3.00, 0)

select vl_pu_operacao = VL_APLICACAO / NR_QUANTIDADE FROM #TMP_APLICACAO

SELECT VL_PU_OPERACAO

PS. How can I have to do to see the result in 16 decimal number :
1034.4666666666666667 ?

I use select vl_pu_operacao = CONVERT(decimal
, but the results is 1034.4666666666 and itīs wrong.

DROP TABLE #TMP_APLICACAO

Marco Guest

2. ## Re: Convert / Decimal / Float

This is by design per bol.

-- e1 / e2 Result Precision: p1 - s1 + s2 + max(6, s1 + p2 + 1); Result
Scale: max(6, s1 + p2 + 1)
-- * The result precision and scale have an absolute maximum of 38. When a
result precision is greater than 38, the corresponding scale is reduced to
prevent the integral part of a result from being truncated.

select result_prec=19-4+16+4+28+1, result_scale=4+28+1

Workaround:

select VL_PU_OPERACAO =
convert(numeric(28,16),convert(numeric(28,16),VL_A PLICACAO) /
FROM #TMP_APLICACAO

--
-oj
RAC v2.2 & QALite!
http://www.rac4sql.net

"Marco" <com.br> wrote in message
news:#phx.gbl...

oj Guest

3. ## Re: Convert / Decimal / Float

Marco,

In addition to oj's solution, you can lower the precision in your
table, if this is possible. You will get better results with

Because you are dividing by NUMERIC(22,16), the calculation is done
to make room for many places on the left of the decimal point, in case
you divide by 0.0000000000000001, and places on the right of the
decimal are sacrificed.

Or you can force the arithmetic to use floating point, but then you
may get different answers that are not exact:

select vl_pu_operacao = 1e0 * VL_...

-- Steve Kass
-- Drew University
-- Ref: A62F699B-36FE-49D6-86F7-AC3377CA7B39

Marco wrote:

Steve Guest

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•