Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

formatting float data types in queries

Posted on 2004-09-01
6
Medium Priority
?
293 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 100 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

926 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