<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Convert string into double in Inventor Programming - iLogic, Macros, AddIns &amp; Apprentice</title>
    <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/convert-string-into-double/m-p/11449769#M143237</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you don't have a fraction symbol - you can use double.Parse&lt;/P&gt;&lt;LI-CODE lang="visual-basic"&gt;Double.Parse(".523")
Double.Parse("-0.523")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For fractional formats, I found two options:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&lt;A href="https://forums.autodesk.com/t5/inventor-ilogic-and-vb-net-forum/convert-fraction-to-decimal/m-p/9751213/highlight/true#M115965" target="_blank" rel="noopener"&gt;https://forums.autodesk.com/t5/inventor-ilogic-and-vb-net-forum/convert-fraction-to-decimal/m-p/9751213/highlight/true#M115965&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For a purely code solution see this stackoverflow post. I have converted the c# to vb.net/iLogic code for you&lt;/P&gt;&lt;P&gt;&lt;A href="https://stackoverflow.com/questions/13903621/convert-a-text-fraction-to-a-decimal" target="_blank" rel="noopener"&gt;https://stackoverflow.com/questions/13903621/convert-a-text-fraction-to-a-decimal&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="visual-basic"&gt;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&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 28 Sep 2022 11:09:28 GMT</pubDate>
    <dc:creator>g.georgiades</dc:creator>
    <dc:date>2022-09-28T11:09:28Z</dc:date>
    <item>
      <title>Convert string into double</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/convert-string-into-double/m-p/11449692#M143236</link>
      <description>&lt;P&gt;Hi guys&lt;/P&gt;&lt;P&gt;I need convert string into double&lt;/P&gt;&lt;P&gt;ex: 1/12 =&amp;gt; 0.8333&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 28 Sep 2022 10:22:28 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/convert-string-into-double/m-p/11449692#M143236</guid>
      <dc:creator>18154093</dc:creator>
      <dc:date>2022-09-28T10:22:28Z</dc:date>
    </item>
    <item>
      <title>Re: Convert string into double</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/convert-string-into-double/m-p/11449769#M143237</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you don't have a fraction symbol - you can use double.Parse&lt;/P&gt;&lt;LI-CODE lang="visual-basic"&gt;Double.Parse(".523")
Double.Parse("-0.523")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For fractional formats, I found two options:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&lt;A href="https://forums.autodesk.com/t5/inventor-ilogic-and-vb-net-forum/convert-fraction-to-decimal/m-p/9751213/highlight/true#M115965" target="_blank" rel="noopener"&gt;https://forums.autodesk.com/t5/inventor-ilogic-and-vb-net-forum/convert-fraction-to-decimal/m-p/9751213/highlight/true#M115965&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For a purely code solution see this stackoverflow post. I have converted the c# to vb.net/iLogic code for you&lt;/P&gt;&lt;P&gt;&lt;A href="https://stackoverflow.com/questions/13903621/convert-a-text-fraction-to-a-decimal" target="_blank" rel="noopener"&gt;https://stackoverflow.com/questions/13903621/convert-a-text-fraction-to-a-decimal&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="visual-basic"&gt;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&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 28 Sep 2022 11:09:28 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/convert-string-into-double/m-p/11449769#M143237</guid>
      <dc:creator>g.georgiades</dc:creator>
      <dc:date>2022-09-28T11:09:28Z</dc:date>
    </item>
    <item>
      <title>Re: Convert string into double</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/convert-string-into-double/m-p/11449781#M143238</link>
      <description>&lt;P&gt;Hi &lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/12578862"&gt;@18154093&lt;/a&gt;.&amp;nbsp; This is what I had in mind for your challenge.&amp;nbsp; Inventor's built-in UnitsOfMeasure object has many useful tools for things like this.&amp;nbsp; Also, I just assumed you were working with inches, but if that is not the case, you can change those aspects within the code.&amp;nbsp; The database units for length are centimeters, and it seems like very few people actually use that as their default document units.&lt;/P&gt;
&lt;LI-CODE lang="general"&gt;Dim oStVal As String = "1/12"
Dim UOM As UnitsOfMeasure = ThisDoc.Document.UnitsOfMeasure
Dim oDblVal As Double = UOM.GetValueFromExpression(oStVal, "in")
oDblVal = UOM.ConvertUnits(oDblVal, "cm", "in")
MsgBox("oDblVal = " &amp;amp; oDblVal,,"")&lt;/LI-CODE&gt;
&lt;P&gt;If this solved your problem, or answered your question, please click &lt;SPAN&gt;&lt;STRONG&gt; ACCEPT SOLUTION &lt;/STRONG&gt;&lt;/SPAN&gt;.&lt;BR /&gt;Or, if this helped you, please click (LIKE or KUDOS) &lt;img class="lia-deferred-image lia-image-emoji" src="https://forums.autodesk.com/html/@7401B55A0A518861312A0F851CD29320/emoticons/1f44d.png" alt=":thumbs_up:" title=":thumbs_up:" /&gt;.&lt;/P&gt;</description>
      <pubDate>Wed, 28 Sep 2022 11:18:53 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/convert-string-into-double/m-p/11449781#M143238</guid>
      <dc:creator>WCrihfield</dc:creator>
      <dc:date>2022-09-28T11:18:53Z</dc:date>
    </item>
  </channel>
</rss>

