Solved

formatting float data types in queries

Posted on 2004-09-01
6
284 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:stromberg45
Comment Utility
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
Comment Utility
>>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
Comment Utility
Typo, this:
such as 123.45 store as 123.4599999999

Should have read:
such as 123.45 store as 123.4499999999
0

Featured Post

Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

Join & Write a Comment

Suggested Solutions

Performance is the key factor for any successful data integration project, knowing the type of transformation that you’re using is the first step on optimizing the SSIS flow performance, by utilizing the correct transformation or the design alternat…
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

728 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now