# convert a real number to decimal

how would i convert a real number to decimal with 15 places to the left of the .

the database has it stored as real ... I simply want to retrive it as decimal using covert or whatever else works
###### Who is Participating?

Commented:

If you want anything after the decimal, you're out of luck.
In the example below, I specified that I want 11 digits of total precision, with 4 of them coming after the decimal point (That leaves 7 to the left of the decimal point).

``````DECLARE @real REAL
SET @real = 123456.8913
SELECT @real
SELECT CAST(@real AS DECIMAL(11,4))
``````
0

Commented:
a real number has only 4 bytes.  15 digit accuracy just isn't there.

DECLARE @real AS REAL, @dec AS DECIMAL
SET @real = 123456789012345
SELECT @real
SET @dec = @real
SELECT @dec
SET @dec = 123456789012345
SELECT @dec

0

Author Commented:
What is the maximum and how would i convert it?
0

Commented:
A real number is accurate to 7 digits left of the decimal.  You can change the data type of the column.  It will convert, but the accuracy of the 15 digits of information was lost when it was stored in a real data type.
0

Author Commented:
That is ok... it can be seven ... what would the code look like
0

Commented:
if you don't want to change the data type in the database, I suppose you could:
select  cast(someRealValue as DECIMAL) as DecimalValue from sometable
0

Author Commented:
How would i specity the precision... for example if i wanted 7 decimal places
0

Commented:
if you want anything after the decimal, you're out of luck.
In the example below, I specified that I want 10 digits of total precision, with 4 of them coming after the decimal point (That leaves 7 to the left of the decimal point).

``````DECLARE @real REAL
SET @real = 123456.8913
SELECT @real
SELECT CAST(@real AS DECIMAL(11,4))
``````
0

Commented:
10 should have been 11
0

Author Commented:
ty
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.