Solved

formatting float data types in queries

Posted on 2004-09-01
6
287 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
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 

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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
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 set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

733 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