VB.net convert numeric text into number

Hi,

I have text in a string 1,234.0 when I try to convert this to a number using
Dim z as string = "1,234.0"
Dim x as integer = Val(z)

it converts the text to number 1

what can I do ?
MichMatAsked:
Who is Participating?
 
Jorge PaulinoConnect With a Mentor IT Pro/DeveloperCommented:
If you want to convert to double you should use Double.Parse() method and replace the "," with nothing.
Like this:
 

        Dim z As String = "1,234.0"
        Dim x As Double = Double.Parse(z.Replace(","c, ""))

Open in new window

0
 
Jorge PaulinoIT Pro/DeveloperCommented:
That's because the "," is the decimal separator and that way it only gets the one. Integer values doesn't allaw to use decimal values.
0
 
MichMatAuthor Commented:
Ok , I thought that Val converts to a double
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
garethh86Commented:
See below, you can't use integer for this, integers are full numbers only (no decimal place), you can use double for what you want.
Dim Z as string = "1,234.56"
 
' Now remove the comma from the string
Dim Z2 as string = z.replace(",", "")
 
'store as double
Dim x as double = Z2

Open in new window

0
 
MichMatAuthor Commented:
Hi Thanks for that

That is the solution to the problem.
0
 
Jorge PaulinoIT Pro/DeveloperCommented:
I don't belive !!!
I have give you the solution (the better) and you give point to the garethh86
That allot unfair!!
0
 
MichMatAuthor Commented:
Ahhhh Crap, Jpaulino the accepted solution was supposed to be yours, I didnt realise that someone else posted what is the same solution. Bugger
0
 
Jorge PaulinoIT Pro/DeveloperCommented:
Ok, someone will fix it!
0
 
MichMatAuthor Commented:
Im quite happy to re-post again under new question
0
 
MichMatAuthor Commented:
Your suggestion is better I'll request attention to this thread and a correction to the points.
0
 
Jorge PaulinoIT Pro/DeveloperCommented:
Thanks !
0
 
garethh86Commented:
Sorry, I made my post at the same time so didn't see your solution jpaulino, otherwise I wouldn't have posted. Nothing untoward, I wasn't trying to steal points. I'm more than happy to have the points moved over if possible, I must admit I was a little surprised when my solution was accepted.

Glad you got it working though!

Thanks

Gareth
0
 
Jorge PaulinoIT Pro/DeveloperCommented:
No problem Gareth and have a nice Easter! :)
0
 
MichMatAuthor Commented:
Thank you for the solution and sorry for the initial mix up
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.