Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
g.georgiades
in reply to: 18154093

Hi,

 

If you don't have a fraction symbol - you can use double.Parse

Double.Parse(".523")
Double.Parse("-0.523")

 

For fractional formats, I found two options:

 

You can have a look at this post where inventor UOM is used to convert the value. You may have to experiment with the units.

https://forums.autodesk.com/t5/inventor-ilogic-and-vb-net-forum/convert-fraction-to-decimal/m-p/9751... 

 

 

For a purely code solution see this stackoverflow post. I have converted the c# to vb.net/iLogic code for you

https://stackoverflow.com/questions/13903621/convert-a-text-fraction-to-a-decimal 

Private Function FractionToDouble(ByVal fraction As String) As Double
        Dim result As Double

        If Double.TryParse(fraction, result) Then
            Return result
        End If

        Dim split = fraction.Split(New Char() {" "c, "/"c})

        If split.Length = 2 OrElse split.Length = 3 Then
            Dim a, b As Integer

            If Integer.TryParse(split(0), a) AndAlso Integer.TryParse(split(1), b) Then
                If split.Length = 2 Then
                    Return a / b
                End If

                Dim c As Integer

                If Integer.TryParse(split(2), c) Then
                    Return a + b / c
                End If
            End If
        End If

        Throw New FormatException("Not a valid fraction.")
End Function