nigel_rennie Posted September 1, 2004 Posted September 1, 2004 well heres how my story goes. I have gotten this information out of a tab deliminated file and now am trying to conver on of the fields to a double. The field is the star rating for a hotel and can be any of 1 - 1.5 - 2 - 2.5 ....etc. It doesnt sound complex however i am getting an error when i try do this - here is the error: An unhandled exception of type 'System.FormatException' occurred in mscorlib.dll Additional information: Input string was not in a correct format. And this comes form the code: Dim tempdbl As Double = System.Convert.ToDouble(tempstring) Apart from this i can only imagine that i have to actually do something with the formatting of the data. It is actually coming through alright as i have viewed it in a text box. Thanks for any help Nigel Quote
Joe Mamma Posted September 1, 2004 Posted September 1, 2004 upload your file. lets have a look Quote Joe Mamma Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized. Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.
techmanbd Posted September 1, 2004 Posted September 1, 2004 If it is a number without anything else try using trim. tempstring.trim There might be spaces you don't see on either side. Quote Live as if you were to die tomorrow. Learn as if you were to live forever. Gandhi
*Experts* Nerseus Posted September 2, 2004 *Experts* Posted September 2, 2004 If there are thousands separators or a decimal format that's not "standard" from your OS, you might need to supply a NumberFormatInfo object. Here's a sample that shows how to expand on the "CurrentInfo", determined by your machine. You can also create a NumberFormatInfo from scratch and fill in all the properties. // The following is 123456.789 in US or 123456,789 in most other countries string s = "123.456,789"; // The following will NOT work on a US system //decimal d = System.Convert.ToDecimal(s); // Specify the exact formatting you expect NumberFormatInfo i = (NumberFormatInfo)NumberFormatInfo.CurrentInfo.Clone(); i.NumberDecimalSeparator = ","; i.NumberGroupSeparator = "."; decimal d = System.Convert.ToDecimal(s, i); -ner Quote "I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
nigel_rennie Posted September 2, 2004 Author Posted September 2, 2004 sorry guys i am just being an idiot I left the column titles in the database - couldnt convert rating to a double - or coarse. Its the little things that make you mad when you over look them - oh well thats programming i guess. Thanks for your help i only noticed it because i was trying to see what i had to trim :) Later Nige Quote
MatP Posted October 27, 2004 Posted October 27, 2004 Hi, I have a similar problem with the error "Input string was not in a correct format" Here's the part of my code I get stuck onto: dim tmpString as String dim myValue as Single tmpString = "0.0000" myValue = System.Single.Parse(tmpString) I tried also with Decimal and Double, and with System.Convert Method... I always get the same error. Thanks for the help, Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.