Jump to content
Xtreme .Net Talk

why the two number after the decimal point are always converted to two zeros


Recommended Posts

Posted

Gentlemen:

 

 

Does anyone knows why the two number after the decimal point are always converted to two zeros with the code below?

 

Example:

 

If the real value was 175.53

 

I only get 175.00

 

Why is this?

 

Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click

       Dim MyRegEx As New Regex("=\s+(?<MyPat>\d+)")
       Dim s As String = txtDataView.Text
       Dim Mc As MatchCollection = MyRegEx.Matches(s)
       Dim M As Match
       Dim i As Integer
       If Mc.Count > 0 Then
           i = 0
           For Each M In Mc
               i += 1
               PutInTextBox(Me, "TextBox" & CStr(i), M.Groups("MyPat").Value)
           Next
       End If

   End Sub



   Private Sub PutInTextBox(ByVal ContainerCtrl As Control, ByVal TBName As String, ByVal msg As String)
       Dim ctl As Control
       For Each ctl In ContainerCtrl.Controls
           If TypeOf ctl Is TextBox And ctl.Name = TBName Then
               ctl.Text = msg
               Exit For
           Else
               PutInTextBox(ctl, TBName, msg)
           End If
       Next

       TextBox75.Text = Sd
       TextBox76.Text = St

   End Sub

Posted
I am just starting to work with regular expressions so excuse me if I'm off base, but doesn't \d+ match one or more instances of a digit? So wouldn;t that stop at the decimal point?
Posted
I am not sure. Since a dot signifies any character except newline, you need a way to override that an just look for a character dot. I'm not sure of the answer.
  • *Experts*
Posted

This is untested, but try this. It adds one optional decimal point followed by 0 or more digits:

 

"=\s+(?<MyPat>\d+[.{0,1}][\d]*)"

 

You might need a backslash in front of the "." but I don't think so.

 

The {0,1} says 0 or 1 occurrences of the ".". The final \d with a * says 0 or more digits. If you really want 0, 1, or 2 digits you can change it.

 

-Nerseus

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...