converting string fractions to double or decimals 
Author Message
 converting string fractions to double or decimals

Hi,
Novice in VB.Net.
I would really appreciate if somebody can tell me how to
code to convert strings like "3/4" or "2 7/8" to their
corresponding decimal values - 0.75 or 2.875 -
Thank you in advance,
JoJo


Tue, 30 Aug 2005 07:04:25 GMT  
 converting string fractions to double or decimals
Hi,
 Can you try this..

        string str = "3";
        double bdl;
        bdl = double.Parse(str);

regards,
Prasanna Kakanoor

Quote:
>-----Original Message-----
>Hi,
>Novice in VB.Net.
>I would really appreciate if somebody can tell me how to
>code to convert strings like "3/4" or "2 7/8" to their
>corresponding decimal values - 0.75 or 2.875 -
>Thank you in advance,
>JoJo

>.



Tue, 30 Aug 2005 12:42:33 GMT  
 converting string fractions to double or decimals
Hello Prasana,


Quote:
>  Can you try this..

>         string str = "3";
>         double bdl;
>         bdl = double.Parse(str);

... but this doesn't work with fractions.

Regards,
Herfried K. Wagner



Tue, 30 Aug 2005 15:46:22 GMT  
 converting string fractions to double or decimals
Hi JoJo,
I dont know any direct way to solve this problem.
Try this. It should work.
Greetings
Daniel

 Private Function Converter(ByVal stDiv As String)
        Dim i, k As Integer, sNum, operator As String
        Dim Result, nNum1, nNum2 As Double
        For i = 0 To stDiv.Length - 1
            If IsNumeric(stDiv.Substring(i, 1)) Then
                sNum = sNum + stDiv.Substring(i, 1)
                nNum1 = CInt(sNum)
                operator = stDiv.Substring(i + 1, 1)
                k = i + 1
            Else
                Exit For
            End If
        Next
        sNum = ""
        For i = k To stDiv.Length - 1
            If IsNumeric(stDiv.Substring(i, 1)) Then
                sNum = sNum + stDiv.Substring(i, 1)
                nNum2 = CInt(sNum)
            End If
        Next
        Select Case operator
            Case "/"
                Return nNum1 / nNum2
            Case "+"
                Return nNum1 + nNum2
            Case "-"
                Return nNum1 - nNum2
            Case "*"
                Return nNum1 * nNum2
            Case Else
                MsgBox("Your input is no valid expession!",
MsgBoxStyle.Critical, "Error")
        End Select
    End Function



Quote:
> Hi,
> Novice in VB.Net.
> I would really appreciate if somebody can tell me how to
> code to convert strings like "3/4" or "2 7/8" to their
> corresponding decimal values - 0.75 or 2.875 -
> Thank you in advance,
> JoJo



Wed, 31 Aug 2005 19:28:59 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Converting fraction string to a decimal value

2. convert a decimal number to fraction.

3. Convert fraction into decimal

4. Converting a double in fraction

5. CR 5.0 -- Convert decimal to fraction?

6. Converting a decimal to a fraction

7. Help with fraction string to double

8. converting string containing binary double to double

9. convert double or decimal to datetime

10. Problem about converting from double to string

11. How to convert string to double or int

12. Convert String to double

 

 
Powered by phpBB® Forum Software