Answered # RegularExpression to convert from Fraction to decimal

sandeepparekh9 109 Discussion Starter tim8w Discussion Starter tim8w Need some help with this Array. I am trying to get the sum of the even numbers and the sum of the odd numbers using a for each loop. I know the answers to what I am trying to achive are sum of even = 84 and the sum of ...

0

can u explain further .. where are you using this?? what appliction some.. screens or code?

0

sandeepparekh9,

I have a DataGridView where the user can enter either fractional info like "1 1/2", "3/4", etc. or decimal values lime "1.5", 0.75", etc. The problem is that I need the data stored as decimal...

0

I ended up using four different RegEx to catch all the cases:

```
sPattern = "((?<whole>\d+) (?<num>\d+)/(?<den>\d+))" ' 1 1/2 case
regExp = New System.Text.RegularExpressions.Regex(sPattern, RegexOptions.Compiled)
m = regExp.Match(dgvc.Value)
If m.Success Then
dDecValue = CInt(m.Groups("whole").Value) + CInt(m.Groups("num").Value) / CInt(m.Groups("den").Value)
Else
sPattern = "((?<num>\d+)/(?<den>\d+))" ' 3/4 case
regExp = New System.Text.RegularExpressions.Regex(sPattern, RegexOptions.Compiled)
m = regExp.Match(dgvc.Value)
If m.Success Then
dDecValue = CInt(m.Groups("num").Value) / CInt(m.Groups("den").Value)
Else
sPattern = "(?<dec>\d+\.?\d+)" ' 0.5 case
regExp = New System.Text.RegularExpressions.Regex(sPattern, RegexOptions.Compiled)
m = regExp.Match(dgvc.Value)
If m.Success Then
dDecValue = CDbl(m.Groups("dec").Value)
Else
sPattern = "(?<whole>\d+)" ' 2 case
regExp = New System.Text.RegularExpressions.Regex(sPattern, RegexOptions.Compiled)
m = regExp.Match(dgvc.Value)
If m.Success Then
dDecValue = CDbl(m.Groups("whole").Value)
Else
MsgBox("Error in value")
End If
End If
End If
End If
```

This question has already been answered. Start a new discussion instead.

Recommended Articles

When I execute this progammatically, I get a table with row heights much larger than when I do this manually.

Note : Sel is the Word.Selection object and the Clipboard contains an Excel Table.

```
public void AddClipboard()
{
Sel.PasteExcelTable(false,false, false);
var t = Sel.Tables[Sel.Tables.Count];
t.AutoFitBehavior(Word.WdAutoFitBehavior.wdAutoFitContent);
}
```

the function that I created to find the ...