Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi All,

I need to read the value -0000000334017 from a file and store them as -3340.17 in Vb.net application.How can i do that?Please help.

Thanks.
Posted
Comments
Richard C Bishop 13-Feb-13 10:57am    
What kind of file? Store it where?
vidkaat 13-Feb-13 10:58am    
its a text file and store it in a dataset.
Chris Reynolds (UK) 13-Feb-13 10:59am    
Is the value held as a string in your file? Is it the only thing in the file?
If it is a string then using the TryParse functions to convert it into a number and then dividing the result by 100 would be one way of doing it.
vidkaat 13-Feb-13 11:04am    
Nope.Its not the only thing in the file i retrieved other data from the file like name,id and stuff.Not sure how to retrieve this value.

I tried row.Substring(87,11) but could not get them.
vidkaat 13-Feb-13 11:07am    
I am stroring it as a Double in my dataset.

1 solution

Hi,

try by writing the below function and pass the text read from the file.
VB
Private Function fnGetNumber(text As String) As Double
	Try
		Return (Convert.ToDouble(text.Trim())) / 100
	Catch ex As Exception
		Return 0.0
	End Try
End Function


this function will the double value and if the text is in correct, this will return 0.0 and also, this will give number with 2 decimal places.

hope it helps.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900