Solved

VB.net convert numeric text into number

Posted on 2009-04-10
15
635 Views
Last Modified: 2012-05-06
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
Comment
Question by:MichMat
  • 6
  • 6
  • 2
15 Comments
 
LVL 48

Expert Comment

by:jpaulino
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

by:MichMat
ID: 24120195
Ok , I thought that Val converts to a double
0
 
LVL 48

Accepted Solution

by:
jpaulino earned 500 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, ""))

Open in new window

0
 
LVL 7

Expert Comment

by:garethh86
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

Open in new window

0
 

Author Comment

by:MichMat
ID: 24120219
Hi Thanks for that

That is the solution to the problem.
0
 
LVL 48

Expert Comment

by:jpaulino
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

by:MichMat
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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 48

Expert Comment

by:jpaulino
ID: 24120238
Ok, someone will fix it!
0
 

Author Comment

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

Author Comment

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

Expert Comment

by:jpaulino
ID: 24120250
Thanks !
0
 
LVL 7

Expert Comment

by:garethh86
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

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

Author Closing Comment

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

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now