End Result to show in decimal form

deafgal

New member
Joined
Oct 21, 2009
Messages
1
Programming Experience
1-3
VB.NET:
Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'Total_CMADataSet.Table1' table. You can move, or remove it, as needed.
        Me.Table1TableAdapter.Fill(Me.Total_CMADataSet.Table1)
    End Sub

    Private Sub Strands_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Strands.TextChanged
        Dim area As Decimal = CDec(ListBox1.SelectedValue)
        Dim strand As Double
        If Double.TryParse(Strands.Text, strand) Then
            strand *= CDec(area)
            Label3.Text = strand.ToString
        End If
    End Sub
End Class

The end result is baffling me here are 2 examples when I debug

Mine: 640.1 * 49 = 31364.9
Debugger: 640.1 * 49 = 31360 ( not right needs to show the correct decimal )

Mine: .775 * 3 = 2.325
Debugger: .775 * 3 = 2.325 ( shows it perfectly???)
 
Last edited:
You're doing something pretty interesting things there...and also don't really understand your question, but I'll give it a try.

First of all, relying on the TextChanged-Event for such things is not really working. The TextChanged-Event is not firing the moment you believe it would...it can be the Text-Property wasn't updated the moment the Event fired, meaning that likely the 1 was missing the moment you debugged it (leaving you with 640. instead of 640.1).

Also I'd suggest to stick to Decimal if you use it once, also, the casting is unnecessary.

VB.NET:
        Dim area As Decimal = CDec(Me.ListBox1.SelectedValue)
        Dim strand As Decimal
        If Decimal.TryParse(Me.Strands.Text, strand) Then
            strand *= area
            Me.Label3.Text = strand.ToString("N0")
        End If

Bobby
 
Back
Top