MichMat
asked on
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 ?
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 ?
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.
ASKER
Ok , I thought that Val converts to a double
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
ASKER
Hi Thanks for that
That is the solution to the problem.
That is the solution to the problem.
I don't belive !!!
I have give you the solution (the better) and you give point to the garethh86
That allot unfair!!
I have give you the solution (the better) and you give point to the garethh86
That allot unfair!!
ASKER
Ahhhh Crap, Jpaulino the accepted solution was supposed to be yours, I didnt realise that someone else posted what is the same solution. Bugger
Ok, someone will fix it!
ASKER
Im quite happy to re-post again under new question
ASKER
Your suggestion is better I'll request attention to this thread and a correction to the points.
Thanks !
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
Glad you got it working though!
Thanks
Gareth
No problem Gareth and have a nice Easter! :)
ASKER
Thank you for the solution and sorry for the initial mix up