Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

Posted
upload your file. lets have a look

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.

Posted

If it is a number without anything else try using trim.

 

tempstring.trim

 

There might be spaces you don't see on either side.

Live as if you were to die tomorrow. Learn as if you were to live forever.
Gandhi
  • *Experts*
Posted

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

"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
Posted

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

  • 1 month later...
Posted

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,

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...