Link to home
Start Free TrialLog in
Avatar of MichMat
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 ?
Avatar of Jorge Paulino
Jorge Paulino
Flag of Portugal image

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.
Avatar of MichMat
MichMat

ASKER

Ok , I thought that Val converts to a double
ASKER CERTIFIED SOLUTION
Avatar of Jorge Paulino
Jorge Paulino
Flag of Portugal image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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

Avatar of MichMat

ASKER

Hi Thanks for that

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!!
Avatar of MichMat

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!
Avatar of MichMat

ASKER

Im quite happy to re-post again under new question
Avatar of MichMat

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
No problem Gareth and have a nice Easter! :)
Avatar of MichMat

ASKER

Thank you for the solution and sorry for the initial mix up