Solved

formatting float data types in queries

Posted on 2004-09-01
6
285 Views
Last Modified: 2012-08-14
i have a number (float) in an sql table when displayed in my flex grid shows about 8 decimals places. wondering if its my flex grid property, ...or can i format/ convert my SQL query to format the number to now show more than two decimal places ?

SQL query=

SELECT     dbo.tePremPurchaseLines.LineNumber, dbo.tePremPurchaseLines.TaxInclusiveTotal, dbo.tePremPurchaseLines.Quantity,
                      dbo.tePremPurchaseLines.TaxInclusiveUnitPrice, dbo.tePremPurchaseLines.Discount, dbo.tItems.ItemNumber,
                      dbo.tePremPurchaseLines.PurchaseID
FROM         dbo.tePremPurchaseLines INNER JOIN
                      dbo.tItems ON dbo.tePremPurchaseLines.ItemID = dbo.tItems.ItemID
WHERE     (dbo.tePremPurchaseLines.PurchaseID = '35')

the offending fields are TaxInclusiveTotal & TaxInclusiveUnitPrice

thanks, peter.
0
Comment
Question by:stromberg45
  • 4
  • 2
6 Comments
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 11959316
You can do this two ways with T-SQL:

1. CAST the float columns to Numeric(18, 2)
2. Change the data type of the float columns to (18, 2)
0
 

Author Comment

by:stromberg45
ID: 11959352
can you show me how to do this in the SQL language, i.e. put it into my query

thanks.
0
 
LVL 75

Accepted Solution

by:
Anthony Perkins earned 25 total points
ID: 11959408
Changing the data type for the column in the table is a better option, however if you insist here it is:

SELECT      dbo.tePremPurchaseLines.LineNumber,
            CAST(dbo.tePremPurchaseLines.TaxInclusiveTotal As numeric(18,2)) As TaxInclusiveTotal,
            dbo.tePremPurchaseLines.Quantity,
            CAST(dbo.tePremPurchaseLines.TaxInclusiveUnitPrice As numeric(18, 2)) As TaxInclusiveUnitPrice,
            dbo.tePremPurchaseLines.Discount,
            dbo.tItems.ItemNumber,
            dbo.tePremPurchaseLines.PurchaseID
FROM      dbo.tePremPurchaseLines INNER JOIN
            dbo.tItems ON dbo.tePremPurchaseLines.ItemID = dbo.tItems.ItemID
WHERE      dbo.tePremPurchaseLines.PurchaseID = '35'
0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 

Author Comment

by:stromberg45
ID: 11959466
i can't change in table, it must be stored as float, because it's currency i'm dealing with.

thankyou for your help.the above solution worked very well.

0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 11959973
>>i can't change in table, it must be stored as float, because it's currency i'm dealing with.<<
If you cannot change the data type to a more appropriate data type (such as money or numeric) than make sure you allow for rounding problems, such as such as 123.45 store as 123.4599999999.  Otherwise it can be a real nightmare.  

The only time you should be using float with currency is if you are dealing with the National Deficit and you need very large numbers, otherwise you are heading for trouble very fast.  The Money data type is an 8 byte value and reaches a maximum of 922,337,203,685,477.5807.
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 11959977
Typo, this:
such as 123.45 store as 123.4599999999

Should have read:
such as 123.45 store as 123.4499999999
0

Featured Post

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

Suggested Solutions

Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

776 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