Solved

Pulling sql server float as string and keep decimal places

Posted on 2006-11-21
6
2,023 Views
Last Modified: 2008-01-09
Hi Experts,
   I have a sqlserver 2000 table that stores several float fields, in vb.net 03' I am pulling these values via sqldatareader.  My question is how can preserve the value stored as is from the table.  Everyway I have tried, truncates decimals on whole numbers.  I would like to pull these values as is with no rounding or truncation. eg if 75.00 is stored in the db I want to pull 75.00 not 75.  I know I can manually cast these values as varchar in sql to get the values or or do codebehind to handle it, but I'm sure there is a way that I can to pull it from the sqldatareader functions as is.  Thanks in advance ....

oh here is an example just in case:

If qdb.queryDbase(sqlState, sqlConn, reader, False, errText, pnErr) Then
            If reader.HasRows Then
                If reader.Read Then
                    ReDim Preserve cspppdInfo(0)
                    cspppdInfo(0) = reader.GetValue(0)
                End If
            Else
                pnNoRecords.Visible = True
                pnContainer.Visible = False
            End If
End if
0
Comment
Question by:dbedoo
  • 3
  • 2
6 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 17995043
The only way that I can think that the decimals get truncated are if the field is treated as an integer, instead of a float.

Bob
0
 
LVL 1

Author Comment

by:dbedoo
ID: 17995146
No its treated as a float but VB just doesn't show the decimal point on whole numbers when pulling this way.    I messed it with it for awhile yesterday and couldn't find a way so I ended up using vb code to handle it.
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 250 total points
ID: 17995163
What happens if you do this?

cspppdInfo(0) = reader("field1").ToString()

Bob
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 18131587
Delete/No Refund

Bob
0
 
LVL 1

Author Comment

by:dbedoo
ID: 18188616
sorry for the delay ;-)  thanks
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

825 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