[2 days left] Whatâ€™s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
Solved

VB.net convert numeric text into number

Posted on 2009-04-10
Medium Priority
679 Views
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 ?
0
Question by:MichMat
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 6
• 6
• 2

LVL 48

Expert Comment

ID: 24120191
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

Author Comment

ID: 24120195
Ok , I thought that Val converts to a double
0

LVL 48

Accepted Solution

jpaulino earned 2000 total points
ID: 24120207
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, ""))
``````
0

LVL 7

Expert Comment

ID: 24120213
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
``````
0

Author Comment

ID: 24120219
Hi Thanks for that

That is the solution to the problem.
0

LVL 48

Expert Comment

ID: 24120227
I don't belive !!!
I have give you the solution (the better) and you give point to the garethh86
That allot unfair!!
0

Author Comment

ID: 24120231
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

LVL 48

Expert Comment

ID: 24120238
Ok, someone will fix it!
0

Author Comment

ID: 24120240
Im quite happy to re-post again under new question
0

Author Comment

ID: 24120243
Your suggestion is better I'll request attention to this thread and a correction to the points.
0

LVL 48

Expert Comment

ID: 24120250
Thanks !
0

LVL 7

Expert Comment

ID: 24122313
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

LVL 48

Expert Comment

ID: 24122322
No problem Gareth and have a nice Easter! :)
0

Author Closing Comment

ID: 31569110
Thank you for the solution and sorry for the initial mix up
0

Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been inâ€¦
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's aâ€¦
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a qâ€¦
Is your data getting by on basic protection measures? In todayâ€™s climate of debilitating malware and ransomwareâ€”like WannaCryâ€”that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.â€¦
Suggested Courses
Course of the Month14 days, 14 hours left to enroll