[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

convert a real number to decimal

Posted on 2010-09-14
10
Medium Priority
?
790 Views
Last Modified: 2012-05-10
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
0
Comment
Question by:troyvw
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
10 Comments
 
LVL 5

Expert Comment

by:David Christal CISSP
ID: 33677350
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 Comment

by:troyvw
ID: 33677368
What is the maximum and how would i convert it?
0
 
LVL 5

Expert Comment

by:David Christal CISSP
ID: 33677399
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
Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

 

Author Comment

by:troyvw
ID: 33677412
That is ok... it can be seven ... what would the code look like
0
 
LVL 5

Expert Comment

by:David Christal CISSP
ID: 33677463
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 Comment

by:troyvw
ID: 33677484
How would i specity the precision... for example if i wanted 7 decimal places
0
 
LVL 5

Expert Comment

by:David Christal CISSP
ID: 33677612
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))

Open in new window

0
 
LVL 5

Expert Comment

by:David Christal CISSP
ID: 33677622
10 should have been 11
0
 
LVL 5

Accepted Solution

by:
David Christal CISSP earned 2000 total points
ID: 33678025

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))

Open in new window

0
 

Author Closing Comment

by:troyvw
ID: 33691585
ty
0

Featured Post

Survive A High-Traffic Event with Percona

Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question