?
Solved

Format a string which is in the form of $10,000 to double

Posted on 2008-11-01
6
Medium Priority
?
331 Views
Last Modified: 2010-04-14
Hi!

I have the following code, I'm passing a strings of the format $12,000. I need to convert them to double,
using CDBL  function is not giving me the desired result.
I need to convert sLineAmt and sCrLineamt to double and then divide sLIneAmt/sCrLineAmt and multiply the result by 100 and then convert the entire result back to string and append a "%" .

Please help em to get the result.
It's extremely urgent. I have  adeadline to meet in another 2 hrs.
Thanks a million in advance.

Private Function Get_Cash_Line_Option_Set_Desc_Percent(ByVal sLineOptSet As String, ByVal sLineAmt As String, ByVal sCrLineAmt As String) As String

        Dim osqlAdapter As New SqlDataAdapter
        Dim oDs As New DataSet
        Dim sDesc As String = String.Empty
        Dim dCreditLineAmt As Double = 0
        Dim dCashLineAmt As Double = 0
        'Dim sOptSet As String() = Nothing
        'Dim strOptSet As String = String.Empty


        Try

            oDs = XML.getxml()
            If Not oDs Is Nothing Then
                If oDs.Tables(0).Rows.Count > 0 Then
                    For Each odr As DataRow In oDs.Tables(0).Rows
                        If Not sCashLineOptSet Is Nothing Then
                            If sCashLineOptSet.Length > 1 Then
                                If (odr("OPTION_SET") = sOptSet) Then
                                    'sDesc = odr("option_set_desc")
                                    If (odr("OPTION_SET") <> "n/a" And odr("OPTION_SET").Contains("/")) Then
                                                               
                                                                               sDesc = (CDbl(sLineAmt) / CDbl(sCrLineAmt)).ToString
                                       
                                        sDesc = sDesc & "%"
                                    Else
                                        sDesc = odr("option_set_desc")

                                    End If

                                End If
                            End If
                        End If


                    Next
                End If

            Else
                sDesc = "n/a"
            End If

                           Return sDesc
        Catch ex As Exception
            Throw ex
        Finally
        End Try
    End Function
0
Comment
Question by:amukta
[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
  • Learn & ask questions
  • 2
6 Comments
 
LVL 8

Accepted Solution

by:
rpkhare earned 1000 total points
ID: 22857997
Try:

doubleVal = System.Convert.ToDouble(stringVal)
0
 
LVL 8

Expert Comment

by:rpkhare
ID: 22858030
I also think that you need to first strip off the $ sign before converting to Double.
0
 
LVL 13

Expert Comment

by:TechTiger007
ID: 22858128
You should be doing something like

dim sValue as string = "$ 48,000"
dim sModifiedValue as string= sValue.Replace("$","").Replace(",","").Trim()
dim dblValue as double = Convert.ToDouble(sModifiedValue)


0
 
LVL 23

Assisted Solution

by:Tony McCreath
Tony McCreath earned 1000 total points
ID: 22920334
This should work.

I've converted it from C# so I might have not got the syntax perfect.
dim newPrice as double = 0.0
dim valid as bool =  Double.TryParse("$12,000",System.Globalization.NumberStyles.Currency,null,out newPrice)

Open in new window

0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

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

Question has a verified solution.

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

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

764 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