Convert float type variable to decimal in Sql Server

0

I have the following code:

DECLARE @A FLOAT

SET @A = 26069175.1934196

SELECT @A

SELECT CAST (@A AS DECIMAL(6,2))

The result I'm looking for is: 26069.19

Which are the first 6 integers from left to right and 2 decimals in the same way.

I have the error:

  

Arithmetic overflow error converting float to data type numeric.

    
asked by ARR 06.11.2018 в 18:25
source

1 answer

1

The problem you have is that you are using a decimal (6.2), that is, a decimal value of 6 digits, of which 4 are for the whole part and 2 for decimals, but 26069175.1934196 has more than 4 digits in their entire part.

I think that to solve this you can do it with a decimal (10.2), something like this:

DECLARE @A FLOAT

SET @A = 26069175.1934196

SELECT @A

SELECT CAST (@A AS DECIMAL(10,2))

Good luck!

    
answered by 06.11.2018 / 18:36
source