09-28-2022
04:09 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
09-28-2022
04:09 AM
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.
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