0

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
5
Contributors
5
Replies
7
Views
6 Years
Discussion Span
Last Post by bLuEmEzzy
0

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.

Edited by codeorder: swapped code for non rounding

0

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
 ..
0
Dim x As String = "96.5471447543161" 
       x = FORMAT(X,"0.0")
       MsgBox(x)

Edited by __avd: Added [code] tags.

0

ignore my prviously reply, and use Double instead of String

Dim x As DOUBLE = 96.5471447543161
x = FORMAT(X,"0.0")
MsgBox(x)

Edited by __avd: Added [code] tags.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.