How to conversions of number I loose my significant values.

I have code below that will take a number (0.3346) in inches and convert it back into mm. The top part of the code after I multiply by 25.4 give me (8.4988D) It should suppose to give me 8.50 mm then what I need to do is take that (8.4988D) value and convert it to a nice round number of 8.50.
I thought the code below would do that with using decimal instead of a double type.

Can anyone offer a suggestion?

 Dim number As Decimal
                        number = Me.txtProbeOffset.Text * 25.4
                        Me.txtProbeOffset.Text = number
                        Select Case number
                            Case 0 To 9
                                If Me.txtProbeOffset.Text.Contains(".") Then
                                    GaugeOffset = Me.txtProbeOffset.Text.Replace(".", "")
                                    GaugeOffset = "0" & GaugeOffset & "0"
                                    If GaugeOffset.Length = 5 Then
                                        GaugeOffset = GaugeOffset.Remove(GaugeOffset.Length - 1)
                                    End If
                                Else
                                    GaugeOffset = "0" & Me.txtProbeOffset.Text & "0" & "0"
                                    If GaugeOffset.Length = 5 Then
                                        GaugeOffset = GaugeOffset.TrimEnd("0")
                                    End If
                                End If
                            Case 10 To 99
                                'If Me.txtProbeOffset.Text.Contains(".") Then
                                '    GaugeOffset = Me.txtProbeOffset.Text.Replace(".", "")
                                '    GaugeOffset = GaugeOffset & "0"
                                'Else
                                GaugeOffset = number & "0" & "0"
                                'End If
                            Case Else
                                Me.ErrWarning.SetError(Me.txtProbeOffset, "Value entered must be in a correct format.MAX value is 5 characters.")
                                WirelessGageSetupMode.Text = "Value entered must be in a correct format.MAX value is 5 characters."
                                ConnectionStatus.BackColor = System.Drawing.Color.Yellow
                                Exit Sub
                        End Select

Open in new window

cmdolcetAsked:
Who is Participating?
 
Éric MoreauSenior .Net ConsultantCommented:
you should use Math.Round (https://msdn.microsoft.com/en-us/library/zy06z30k(v=vs.110).aspx):

number = Math.Round(Me.txtProbeOffset.Text * 25.4, 2)

Open in new window

1
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.