i have a calculation and the results are outputting like so 96.5471447543161

i would like to format this text box to only show 96.54 (no rounding)

below is the code i am using.

Dim d1 As Double = Nothing

        d1 = ((Val(Me.txtgoodsout.Text) + (Val(Me.txtnrft.Text))) / Val(Me.txtrawin.Text)) * 100

        Me.txtyield.Text = d1

See if this helps.

Dim x As String = "123.4567"
        x = x.Substring(0, x.IndexOf(".") + 3)
        MsgBox(x)

Btw, I believe Val is vb6 term and might get outdated soon.

Use Math.Truncate method

Dim d1 As Double = Nothing
 d1 = 22.345678

 d1 = Math.Truncate(d1 * 100) / 100 // 22.34
 d1 = Math.Truncate(d1 * 1000) / 1000 // 22.345
 ..
Dim x As String = "96.5471447543161" 
       x = FORMAT(X,"0.0")
       MsgBox(x)

ignore my prviously reply, and use Double instead of String

Dim x As DOUBLE = 96.5471447543161
x = FORMAT(X,"0.0")
MsgBox(x)
txtyield.text = FormatNumber(d1, 2)
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.