Monday, September 7, 2009

Posteando en StackOverflow

Esta era mi pregunta


I want to convert my float field into a decimal field; I want a precision of 11,2 in my decimal field, but when I tried to change the type of my field(example: Amount) I get an error: "Arithmetic overflow error converting float to data type numeric. The statement has been terminated." My field is decimal(11,2) at the table, and my max and min values are: 1,603,837,393.70 < -- > -1,688,000,000.00(amount).
select Id,AccountId, cast(Amount as decimal(12,2)) as Amount,
cast
(AmountB as decimal(12,2)) as AmountB
FROM myTable

Esta fue la respuesta.

But a value of "1,603,837,393.70" would require decimal(12,2) - 12 digits in all, 2 after the decimal point.

Maybe you misinterpreted the way the decimal(11,2) works? This would mean total of 11 digits - 9 to the left, 2 to the right of the decimal point.

See the MSDN docs for decimal and numeric types:

decimal[ (p[ , s] )] and numeric[ (p[, s] )]

p (precision)

The maximum total number of decimal digits that can be stored, both to the left and to the right of the decimal point.


No comments: